Code: Select all
var := "notepad++.exe"
hwnd := WinActive("ahk_exe " var)
HotIfWinActive "ahk_id " hwnd
Hotkey "^Space", "testCB"
HotIf
g := Gui.New("+AlwaysOnTop")
g.Add("Button","vBtn1","Test").OnEvent("click","gui_click")
g.Add("Button","vBtn2","Reset").OnEvent("click","gui_click")
g.Show("w200")
gui_click(ctl,info) {
If (ctl.Name = "Btn1") {
WinActivate "ahk_exe firefox.exe"
HotIfWinActive "ahk_exe firefox.exe"
Hotkey "^+Space", "testCB"
HotIf
} Else If (ctl.Name = "Btn2") {
HotIfWinActive "ahk_exe firefox.exe"
Hotkey "^+Space", "Off" ; shutting of hotkey is context sensitive?
HotIf
}
}
testCB(thisKey) {
msgbox "hotkey: " thisKey
}
Another thing that confused me is that the a112 help docs for HotIfWin... states:
As far as I can tell that's what I'm trying to do with Hotkey "^+Space", "Off", but it doesn't seem to work unless I add HotIfWinActive ... in the line above.... In other words, Hotkey A_ThisHotkey, "Off" turns off the current hotkey even if it is context-sensitive.
Also, if I try to use HotIfWinExist, then it seems to set the hotkey as global, instead of being context sensitive with the specified window.
I'm just trying to wrap my brain around how this is meant to work. Basically I'm trying to set hotkeys dynamically so they can be user defined. In my larger script, it works on startup, but subsequent uses doesn't work at all.