Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

AHK-generated vs Genuine: Modifiers and Keys

  • Please log in to reply
1 reply to this topic
  • Members
  • 1 posts
  • Last active: Jun 21 2014 10:23 PM
  • Joined: 18 Jun 2014

Edit1: Curse me, posted in wrong sub-forum :c


Edit2: Solved by {Blind}!





Original Post:


A few words of introduction : I've been scripting in AHK and browsing the forum for at least 2 years now and I believe I've got a decent understanding of all the nooks and crannies (save for DLL calls).


I will refer to the events sent by AHK's Send as "AHK-generated" and events sent by the underlying OS (keys not modified by AHK) as "genuine". Also, whenever I mention a "modifier", I mean any of the Left/Right Shift/Control/Alt, whereas "key" will stand for any key other than modifiers. "Physical" will refer to an actual key on the keyboard.


One more thing to bring up before I move on to the issue: I never questioned why, found it out during my learning period and simply accepted it, but genuine modifiers do NOT modify AHK-generated keys. However, AHK-generated modifiers DO modify genuine keys as well as AHK-generated keys.

Heart of the matter: the only way to modify an AHK-generated key is by using an AHK-generated modifier. This is the universal truth I have never questioned.


Having said that, the easiest way to present the problematic scenario is with this little script:

  Send {x Down}
  KeyWait, p
*p Up::
  Send {x Up}

  Send {LShift Down}
  KeyWait, LShift
*LShift Up::
  Send {LShift Up}

This isn't the actual code from my script, but it's the most compact way of presenting the issue.
It's pretty straightforward - pressing physical P generates an "X Down" event and releasing physical P generates an "X Up" event - therefore the logical state of X is Down for as long as physical P is held. Same goes for LShift.


In the abovementioned script, holding physical LeftShift and pressing physical P does NOT produce an upper case X, even though the logical state of LShift is Down while the AHK-generated X appears.  For genuine keys, this works as intended.
Now the interesting part:

if you change the AHK-generated key to RShift instead of LShift ( Send {LShift Down} -> Send {RShift Down} , same for Up )


if you change the Physical key to ANY other key ( *LShift:: -> *z:: )

it will work as intended - that is, the AHK-generated X will be capital.


Thus, The ONLY scenario where the AHK-generated X is NOT modified by the AHK-generated LShift is when the latter is bound to its original Physical key.

It stays true for both sides (Left/Right) of all three modifier keys (Shift, Control, Alt).


In short: binding AHK-generated modifier to its original physical key will make it modify ONLY genuine keys.


Is there some interference between logical and physical states occuring? Is this intended? If it is, what is logic behind such behaviour?



PS. I tried my best to present the matter as I see it AND as clear as possible at the same time. If anything's unclear, do not hesitate to ask for further explanation. 

  • Members
  • 5 posts
  • Last active: Jul 09 2015 09:52 AM
  • Joined: 28 May 2015

Interesting. Nice analysis and explanation. Thank you.