My specific setup is a last generation, top of the line X1 Carbon running fully patched Windows 10. (While I doubt hardware or OS matters here, I'm including just in case.) The problem has been with me for years and still appears in the latest AHK release which at this time is 1.1.25.01, 64-bit.
Some things I've tried without success:
(1) KeyWait at the beginning of the macro, e.g.
Even with this sort of code, I still find, e.g., LWIN often stuck down.
(2) "ReleaseModifiers" script, e.g.
ReleaseModifiers(timeout := "") ; timeout in ms
static aModifiers := ["Ctrl", "Alt", "Shift", "LWin", "RWin"]
startTime := A_Tickcount
if (timeout && A_Tickcount - startTime >= timeout)
return 1 ; was taking too long
for Index, Key in Keys
if getkeystate(Key, "P")
else if getkeystate(Keys, "P")
return Keys ;keys!
And then calling the script as ReleaseModifiers(500) at the end of every macro.
Also tried solutions posted elsewhere, e.g. https://autohotkey.com/boards/viewtopic.php?f=5&t=26760 and https://autohotkey.com/board/topic/9409 ... ways-down/
The only thing I've found that consistently gets me out of the stuck key situation is to kill and relaunch AHK, which is not a terribly convenient workaround.
Hoping someone can help end this long national nightmare!