Jump to content

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


Recommended Posts

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

Link to comment
Share on other sites

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

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

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

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

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

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...