Sign in to follow this  
Followers 0
chenxu

How to make a 'private' hot key with AutoIt?

8 posts in this topic

We can define a hot key in our scripts by HotKeySet(), but, it is a global hot key, I now need to make a private one, which is only work when the AutoIt GUI is activated? How to do this?

Share this post


Link to post
Share on other sites



In your GUI's while loop make a condition:

Global $hotKeyIsSet

;Create $GUI here

While 1
    If WinActive("Title of window") AND $hotKeyIsSet = 0 Then 
        HotkeySet("^+Q", "hotkeyfunc")
        $hotKeyIsSet = 1
    EndIf
    If Not WinActive("Title of window") AND $hotKeyIsSet = Then
        HotkeySet("^+Q")
        $hotKeyIsSet = 0
    EndIf

WEnd

Regards,Josh

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Use GUISetAccelerators muttley

Or do the Check in

WM_ACTIVATEAPP 0x001C

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

HotKetSet("key" , "func")

Func func()
HotKeySet("key")
Send("key")
If WinActive($yourgui) then
;action
EndIf
HotKetSet("key" , "func")
EndFunc


Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites

HotKetSet("key" , "func")

Func func()
HotKeySet("key")
Send("key")
If WinActive($yourgui) then
;action
EndIf
HotKetSet("key" , "func")
EndFunc

When are you suggesting calling that function? If you do it every time it loops through the while, then you are doing a ton of redundant hotkeysets. Also why the Send? (Not being critical, just curious)

That also seems to be redundant because you are clearing the hotkey, then resetting it if the window is open instead of setting the hotkey once when the window becomes active, and clearing it once when it isn't.


Regards,Josh

Share this post


Link to post
Share on other sites

Why is everyone putting too much thought into this?

$hGUI = GUICreate("Test", 500, 500)
$hDummy = GUICtrlCreateDummy()
$hDummy2 = GUICtrlCreateDummy()
Dim $azAccelerators[2][2] = [["^e", $hDummy],["^y", $hDummy2]]
GUISetAccelerators($azAccelerators)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case - 3, $hDummy
            Exit
        Case $hDummy2
            MsgBox(0, "Hey", "Sup")
    EndSwitch
WEnd

Ctrl+E Exits, Ctrl+Y Greets you.

Share this post


Link to post
Share on other sites

Why is everyone putting too much thought into this?

$hGUI = GUICreate("Test", 500, 500)
$hDummy = GUICtrlCreateDummy()
$hDummy2 = GUICtrlCreateDummy()
Dim $azAccelerators[2][2] = [["^e", $hDummy],["^y", $hDummy2]]
GUISetAccelerators($azAccelerators)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case - 3, $hDummy
            Exit
        Case $hDummy2
            MsgBox(0, "Hey", "Sup")
    EndSwitch
WEnd

Ctrl+E Exits, Ctrl+Y Greets you.

My AutoIt claim the error:

ERROR: GUISetAccelerators(): undefined function.

Why?

Share this post


Link to post
Share on other sites

My AutoIt claim the error:

ERROR: GUISetAccelerators(): undefined function.

Why?

You must have an old version. Update.

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