How to trigger an action if there's only one key being pressed?
The clarifications added to the original post were helpful.
Shift is not like a normal hotkey, so the order you press the keys in matters. For example, pressing Ctrl+Shift does not necessarily trigger the same hotkey as pressing Shift+Ctrl.
Also just for info, hotkey definitions fire on the key-up event, unless you have a separate "key up" hotkey definition (for example if Shift Up::
is added to the script, then the original Shift::
code now fires on Shift Down
, where-as previously it would fire on Shift Up
)
At any rate, if you put a tilde (~
) in front of a hotkey definition it will execute your code but doesn't block the key press at all from going through, so for any number of special Shift
combinations that you don't want to trigger, you can try turning the hotkey off and then back on. When multiple hotkey definitions are stacked it executes the same code at the bottom for any of them, until the Return statement...
~+LControl::
~+RControl::
~+LAlt::
~+RAlt::
~Shift & Alt::
~Shift & Control::
~^Shift::
~!Shift::
Tooltip % "A_ThisHotkey=" A_ThisHotkey
Hotkey, Shift, Off
KeyWait, Shift
Hotkey, Shift, On
Sleep 100 ; comment this out if not debugging
ToolTip
Return
Shift::MsgBox
I started out with the debug code above, but I don't think it even needs anything to execute as long as there are hotkeys defined for the use cases you don't want to trigger... i.e., this appears to work just as well...
~+LControl::
~+RControl::
~+LAlt::
~+RAlt::
~Shift & Alt::
~Shift & Control::
~^Shift::
~!Shift::
Return
Shift::MsgBox
If you want to see the difference in behavior between different orders of keystrokes though, leave off of the first few hotkey definitions and run this code below, which will show you the difference it makes in pressing Ctrl+Shift, vs. Shift+Ctrl.
Without the other hotkey definitions, this shows that it allows you to distinguish the key order, which allows you to actually have a Ctrl+Shift hotkey that does not fire on Shift+Ctrl (i.e., it's a 'feature', not a bug)
~^Shift::
~!Shift::
Tooltip % "A_ThisHotkey=" A_ThisHotkey
Hotkey, Shift, Off
KeyWait, Shift
Hotkey, Shift, On
Sleep 100 ; comment this out if not debugging
ToolTip
Return
Shift::MsgBox