Code: Select all
*#up::MouseMove, 0, -10, 0, R ; Win+UpArrow hotkey => Move cursor upward
*#Down::MouseMove, 0, 10, 0, R ; Win+DownArrow => Move cursor downward
*#Left::MouseMove, -10, 0, 0, R ; Win+LeftArrow => Move cursor to the left
*#Right::MouseMove, 10, 0, 0, R ; Win+RightArrow => Move cursor to the right
*<#RCtrl:: ; LeftWin + RightControl => Left-click (hold down Control/Shift to Control-Click or Shift-Click).
SendEvent {Blind}{LButton down}
KeyWait RCtrl ; Prevents keyboard auto-repeat from repeating the mouse click.
SendEvent {Blind}{LButton up}
return
*<#AppsKey:: ; LeftWin + AppsKey => Right-click
SendEvent {Blind}{RButton down}
KeyWait AppsKey ; Prevents keyboard auto-repeat from repeating the mouse click.
SendEvent {Blind}{RButton up}
return
Yes, it does do that, but is also has other significant side-effects (It does not work when two hotkeys do this).
I have long been campaigning to alter the documentation to advise people to avoid KeyWait or GetKeyState loops in hotkeys, and this seems to be the only case where doing KeyWait inside a hotkey serves a valid use.
In order to do the above code without a KeyWait (And keeping the repeat suppression), you would need to do this:
Code: Select all
rcState := 0
akState := 0
*#up::MouseMove, 0, -10, 0, R ; Win+UpArrow hotkey => Move cursor upward
*#Down::MouseMove, 0, 10, 0, R ; Win+DownArrow => Move cursor downward
*#Left::MouseMove, -10, 0, 0, R ; Win+LeftArrow => Move cursor to the left
*#Right::MouseMove, 10, 0, 0, R ; Win+RightArrow => Move cursor to the right
*<#RCtrl:: ; LeftWin + RightControl => Left-click (hold down Control/Shift to Control-Click or Shift-Click).
if (rcState)
return ; Suppress repeats
rcState := 1
SendEvent {Blind}{LButton down}
return
*<#RCtrl up::
SendEvent {Blind}{LButton up}
rcState := 0
return
*<#AppsKey:: ; LeftWin + AppsKey => Right-click
if (akState)
return
akState := 1
SendEvent {Blind}{RButton down}
return
*<#AppsKey up::
SendEvent {Blind}{RButton up}
akState := 0
return
So if we added a repeat suppression prefix (eg @1::), then this would remove the need for KeyWait to do repeat suppression, meaning that we can more easily remove these examples from the docs, without affecting the functionality of the code.
My ultimate goal here is to remove all the examples which suggest that using a blocking wait inside a hotkey is a good idea, I am getting really sick of having to explain how hotkey threads work to noobs, because they blindly follow the examples in the documentation (Which gives them no warnings that the technique it is showing them is fundamentally flawed), and which work for the sample code in isolation, but once you try to use it in your script (Which has more than one hotkey), they stop working properly. I am literally having to explain this multiple times a day at times. It's ridiculous.