#If and variable Hotkey key
Posted: 27 Jan 2014, 04:38
I can't figure out how to have variable Hotkey key and use #If
For example, in code below, variable Hotkey key set to "F1", and context-sensitivity depends on active window (IfWinActive)
[code]MyHotkey := "F1"
Hotkey, IfWinActive, ahk_class Shell_TrayWnd
Hotkey, %MyHotkey%, MyHotkeySub, on
Hotkey, IfWinActive
return
MyHotkeySub:
MsgBox,,, % A_ThisHotkey, 1
return[/code]
Now I want to have context-sensitivity which depends on Window under mouse - so I have to use #If
I know how to do it without having variable Hotkey key;
[code] #If MouseIsOver("ahk_class Shell_TrayWnd")
F1::
MsgBox,,, % A_ThisHotkey, 1
return
#If
MouseIsOver(WinTitle) {
MouseGetPos,,, Win
return WinExist(WinTitle . " ahk_id " . Win)
}[/code]
But how to do it with variable Hotkey key, like in first example (MyHotkey := "F1")?
This not-working example will give you idea of what I want:
[code] MyHotkey := "F1" ; variable Hotkey key
return
#If MouseIsOver("ahk_class Shell_TrayWnd")
%MyHotkey%:: ; variable Hotkey key
MsgBox,,, % A_ThisHotkey, 1
return
#If
MouseIsOver(WinTitle) {
MouseGetPos,,, Win
return WinExist(WinTitle . " ahk_id " . Win)
}[/code]
How to do that?
For example, in code below, variable Hotkey key set to "F1", and context-sensitivity depends on active window (IfWinActive)
[code]MyHotkey := "F1"
Hotkey, IfWinActive, ahk_class Shell_TrayWnd
Hotkey, %MyHotkey%, MyHotkeySub, on
Hotkey, IfWinActive
return
MyHotkeySub:
MsgBox,,, % A_ThisHotkey, 1
return[/code]
Now I want to have context-sensitivity which depends on Window under mouse - so I have to use #If
I know how to do it without having variable Hotkey key;
[code] #If MouseIsOver("ahk_class Shell_TrayWnd")
F1::
MsgBox,,, % A_ThisHotkey, 1
return
#If
MouseIsOver(WinTitle) {
MouseGetPos,,, Win
return WinExist(WinTitle . " ahk_id " . Win)
}[/code]
But how to do it with variable Hotkey key, like in first example (MyHotkey := "F1")?
This not-working example will give you idea of what I want:
[code] MyHotkey := "F1" ; variable Hotkey key
return
#If MouseIsOver("ahk_class Shell_TrayWnd")
%MyHotkey%:: ; variable Hotkey key
MsgBox,,, % A_ThisHotkey, 1
return
#If
MouseIsOver(WinTitle) {
MouseGetPos,,, Win
return WinExist(WinTitle . " ahk_id " . Win)
}[/code]
How to do that?