Jump to content

Hotkey only for GUI


sugi
 Share

Recommended Posts

Is there a way to create a hotkey that's only active while the GUI is the active window?

I guess it would be possible by using an Adlib function but this looks more like a workaround to me (something like If WinGetHandle('') = $GUIHandle then HotKeySet('{Key}', ....) Else HotKeySet ('{Key}'))

Drawback is that it would only update the status of the hotkey every 250 ms (yes, I know I can change this delay but I don't like the idea of polling 10 times a second...) and this might create problems with other scripts when I automate my AutoIt GUIs.

Link to comment
Share on other sites

In the HotKey routine, check to see if the window has the focus. If not, drop out.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

What about making buttons out of view? Is possible that buttons never take focus using Tab?

<{POST_SNAPBACK}>

Maybe I'm still to tired... but what does it help to have a button when I want a hotkey (TAB, ESC, F1, etc.) that's only active while the GUI window is focused?
Link to comment
Share on other sites

Maybe I'm still to tired... but what does it help to have a button when I want a hotkey (TAB, ESC, F1, etc.) that's only active while the GUI window is focused?

<{POST_SNAPBACK}>

Yeah, pretty weird solution...

I'm gonna try to create a nice UDF for this.

Because I need one myself.

Link to comment
Share on other sites

Maybe I'm still to tired... but what does it help to have a button when I want a hotkey (TAB, ESC, F1, etc.) that's only active while the GUI window is focused?

<{POST_SNAPBACK}>

Well. You cant set every type of hotkey, but you CAN set any ALT+x combinations. Just setting the Button text as &d, &f, ect... Edited by ezzetabi
Link to comment
Share on other sites

Here it is.

(The first line is an example.)

ActHotKey("My Calculator", "{ENTER}", "Process")

;===============================================================================
;
; Description:    Checks if a given title matches the current window to set a hotkey.
; Syntax:          ActHotKey($Title, $HotKey, $Function)
; Parameter(s):  $Title      - The title of the window.
;                   $HotKey      - The hotkey you want to use.
;                   $Function   - The function that the hotkey should execute.
;
; Requirement(s):   AutoIt v3.0.102
; Return Value(s):  On Success - Sets the hotkey and returns 1: Current window matches the title.
;                  On Failure - Returns 0 if the current window doesn't match the title.
;
; Author(s):        "SlimShady"
; Note(s):        none
;
;===============================================================================
Func ActHotKey($Title, $HotKey, $Function)
    If WinGetTitle("") == $Title Then
        HotKeySet($HotKey, $Function)
        Return 1
    Else
        HotKeySet($HotKey)
        Return 0
    EndIf
EndFunc
Link to comment
Share on other sites

I've now implemented it the way Nutster suggested:

Global $GUIHandle
[...]
$GUIHandle = GUICreate("CG-IT Admin-GUI " & $Version, 480, 482)
HotKeySet('{TAB}', 'TABSearch')
[...]
Func TABSearch()
   If WinGetHandle('') = $GUIHandle Then
      HotKeySet('{TAB}'); This is only because the next function can take a few minutes and I don't want it running severall times
      FilterComputers(GUIRead($input_1))
      HotKeySet('{TAB}', 'TABSearch')
      Return
   EndIf
   HotKeySet('{TAB}')
   Send('{TAB}')
   HotKeySet('{TAB}', 'TABSearch')
EndFunc

But I still don't like the idea of having every usage of the TAB key going through my script.

Edited by sugi
Link to comment
Share on other sites

So... watch for the minimize message, then remove the hotkey.  Then watch for the restore message and re-add the hotkey.

<{POST_SNAPBACK}>

This only works when the GUI is minimized everytime it's not active. But if I just click on a different window the hotkey is still active.

If there was an Inactive message, this would help alot. But I haven't found it in the helpfile which means I'd have to create one myself by looping and checking if my GUI is the active window.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...