#If and variable Hotkey key Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
potkon

#If and variable Hotkey key

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?
potkon

Re: #If and variable Hotkey key  Topic is solved

27 Jan 2014, 04:40

P.S. Why BBCode doesn't work? I put my code in [code][/code] tags... :(
User avatar
LazyMan
Posts: 26
Joined: 14 Jan 2014, 00:22
Location: peering out from behind my favorite rock

Re: #If and variable Hotkey key

27 Jan 2014, 12:32

potkon wrote:P.S. Why BBCode doesn't work? I put my code in tags... :(
I think BBCode does not work with guest accounts.
User avatar
LazyMan
Posts: 26
Joined: 14 Jan 2014, 00:22
Location: peering out from behind my favorite rock

Re: #If and variable Hotkey key

27 Jan 2014, 13:25

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)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Rohwedder and 185 guests