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?
#If and variable Hotkey key Topic is solved
Re: #If and variable Hotkey key Topic is solved
P.S. Why BBCode doesn't work? I put my code in [code][/code] tags...
Re: #If and variable Hotkey key
I think BBCode does not work with guest accounts.potkon wrote:P.S. Why BBCode doesn't work? I put my code intags...Code: Select all
Re: #If and variable Hotkey key
Hotkey wrote:Expression must match exactly the text of an existing #If Expression
Code: Select all
MyHotkey := "F1"
Hotkey, If, MouseIsOver("ahk_class Shell_TrayWnd")
Hotkey, %MyHotkey%, MyHotkeySub, on
Hotkey, If
Return
#If MouseIsOver("ahk_class Shell_TrayWnd")
MyHotkeySub:
MsgBox, , , % A_ThisHotkey, 1
Return
#If
MouseIsOver(WinTitle) {
MouseGetPos, , , Win
Return WinExist(WinTitle " ahk_id " Win)
}
Re: #If and variable Hotkey key
Thank you so much!
[SOLVED]
[SOLVED]
Who is online
Users browsing this forum: Kellyzkorner_NJ and 159 guests