#If and ~LButton Up confusion

Get help with using AutoHotkey and its commands and hotkeys
Posts: 46
Joined: 15 Jan 2014, 19:09

#If and ~LButton Up confusion

13 Jul 2014, 21:58

Here is a simple test script.

Code: Select all


#If (Test() = 1)
~LButton Up::OutputDebug, TEST LBUTTON UP %A_ThisHotkey% ; the first hotkey line
LButton Up::OutputDebug, NORMAL LBUTTON UP %A_ThisHotkey% ; the second hotkey line

  Return 0
When executed, the script shows "NORMAL LBUTTON UP ~LButton Up" on each press of LButton. If the script is changed, and the "~" is removed from the first hotkey line (the TEST LBUTTON line), then the script shows "NORMAL LBUTTON UP LButton Up" on each press of LButton.

In both cases the hotkey that is actually executed is the second one. The hotkey that actually fires, as I understand it, is "LButton Up", or else this second hotkey line would not be executed. Yet when this hotkey "LButton Up" is fired, the value of A_ThisHotkey is acutally "~LButton Up" (in the original unchanged script).

Why? And why would the presence of a different hotkey specification change the value seen by A_ThisHotkey? How should I think of the meaning of "~"? I can program around this but I don't actually understand why I am seeing a ~ value in A_ThisHotkey for a hotkey that is not defined with a ~.
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: #If and ~LButton Up confusion

14 Jul 2014, 03:48

It's just the "name" of the hotkey. What you are using is two different "#If" variants of the same hotkey, not two separate hotkeys. ListHotkeys confirms this. They are activated by the same combination of keys, but the two variants have different options. Because they are counted as the same hotkey, if you were to remove #If you would get a "duplicate hotkey" error.
Hotkey command wrote:When a hotkey is first created -- either by the Hotkey command or a double-colon label in the script -- its key name and the ordering of its modifier symbols becomes the permanent name of that hotkey as reflected by A_ThisHotkey.
Hotkey wrote:Notes: 1) Unlike the other prefix symbols, the tilde prefix is allowed to be present on some of a hotkey's variants but absent on others

Re: #If and ~LButton Up confusion

14 Jul 2014, 09:27

OK, sort of -- perhaps I guess I understand, maybe. I think this must be special to tilde -- not the order of the of the modifiers on a hotkey (the first one seen defines the ordering reported in A_ThisHotkey -- that is clear) but whether the modifier (tilde) is shown as part of the key name. Tilde is sort of special in meaning in any case. Actually, then, maybe I do understand.

Thanks, Lexicos.
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: #If and ~LButton Up confusion

14 Jul 2014, 21:09

The same applies to $ (the "use hook" modifier). Both modifiers affect the behaviour of the hotkey but not which combinations of keys can trigger them.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], FanaticGuru, Google [Bot], vanil and 53 guests