The current behaviour is correct.
As Helgef has pointed out,
a::b consists of two hotkeys:
*a and
*a up. The test script has a third hotkey:
a.
Each hotkey has an activation trigger, while each
variant of the hotkey may have conditions for firing. The activation triggers are:
- a: Press 'A' with exactly none of the standard modifiers pressed.
- *a: Press 'A' with any combination of modifiers, or none.
When both hotkeys are implemented with the hook (which allows AutoHotkey to control which hotkey should be activated for each keyboard event),
a is given precedence over
*a since the opposite would prevent
a from ever triggering. Having both hotkeys present can still be useful, because
*a will trigger if any of the modifier keys is held in combination with 'A'. For the test script, this means
Shift+
A will activate the remapping if the "user" window is active, even though
A on its own runs Notepad.
For a given hotkey, the global variant is used only if no conditional variant is active. However, the test script has only one variant of each hotkey. That is:
- a: global/unconditional
- *a: #IfWinActive user
So there is another simple solution: add a variant for
a to override the global variant but perform the same action as
*a.
Code: Select all
#IfWinActive user
a::
a::b
a up::
SetKeyDelay -1
Send {Blind}{b up}
return
#IfWinActive
a::Run, notepad
Since
a::b expands to the hotkey
*a:: followed by the hotkey
*a up::,
a:: is actually targeting the same subroutine as
*a. That only sends key-down, so it is necessary to duplicate the key-up hotkey. It isn't always necessary to duplicate the remapping in full; for instance, this might be sufficient:
Code: Select all
a::
*a::Send {Blind}{b down}
a up::
*a up::Send {Blind}{b up}
...or sometimes this: