I started by trying to copy my working code for longpress of the Escape key...
Code: Select all
$Escape::
KeyWait, %A_ThisHotkey%, T.5
If %ErrorLevel%
WinMinimize, A
else
Send {Escape}
Return
$Home::
KeyWait, %A_ThisHotkey%, T.5
If %ErrorLevel%
Send {End}
else
Send {Home}
Return
So I messed around a little and found that there is a difference between the firing of an Escape hotkey vs a Home hotkey...
Code: Select all
$Escape::msgbox %A_ThisHotkey% ; this shows "Escape"
$Home::msgbox %A_ThisHotkey% ; this shows "$Home"
So next I just replaced the A_ThisHotkey reference for the Home hotkey to use the direct keyname...
Code: Select all
$Home::
KeyWait, Home, T.5
If %ErrorLevel%
Send {End}
else
Send {Home}
Return
I messed around some more and found that the "Send {Home}" in the else statement was getting fired when releasing the Home key. (Turns out my Escape longpress hotkey was doing the same thing, but I never noticed because it was just an extra Escape key press which didn't do anything on the next window that took focus after the previous one was minimized.)
So why does the key get sent again when releasing the physical key? I'm using the $ modifier so the keypress shouldn't trigger the key itself, but I don't think that's the issue. If I hold down the Home key, the End key does get sent, proving the KeyWait line and if statement are doing their job using ErrorLevel. So it seems like the Home key is getting sent once when I press the physical key down, and again when I release it, triggering the hotkey again...and since the second time is fast, the KeyWait check doesn't timeout and therefore we skip the if statement and go right to the else and send the Home key a second time.
Thoughts on this? I'm kind of stumped and it's been an hour and a half for me.