Sign in to follow this  
Followers 0
sugi

Hotkey only for GUI

12 posts in this topic

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.

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

Well, that would be one way. But if the window is not active I have to unregister the HotKey, then Send() the HotKey I'm using and reregister the Hotkey.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Just hide them!

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0