Unexpected keyup event sent by UP hotkeys Topic is solved

Report problems with documented functionality
mobiusx02
Posts: 2
Joined: 07 Feb 2018, 02:56

Unexpected keyup event sent by UP hotkeys

Post by mobiusx02 » 04 Jul 2020, 10:47

I found an inconsistent and unexpected behaviour when using the Hotkey command to disable UP hotkeys with UP hotkeys. I'm on v1.1.33.00 and can reproduce it on Win 8.1 and Win 10 2004.

Edit: I just found this actually has nothing to do with Hotkey command. The script with no Hotkey command also has the unexpected behaviour.

Code: Select all

#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%

#InstallKeybdHook
#UseHook On

LShift Up::return

z Up::return
Code with Hotkey command:
Spoiler
Run the above script, press and release LShift or z for the first time gives the KeyHistory below as expected. But the actual key events sent are incorrect when I check it with a key logger.

A0 02A s d 8.13 LShift
A0 02A h u 0.16 LShift
5A 02C s d 0.48 z
5A 02C h u 0.14 z

Run the script, put cursor in key logger textbox, press and release LShift or z for the first time. No z key event logged but an LShift keyup event is logged. This LShift keyup event is not expected going by the documentation or KeyHistory. I verified this with both key loggers linked below. This problem also applies to LAlt LCtrl LWin so maybe the bug is related to modifier keys?

https w3c.github.io /uievents/tools/key-event-viewer.html
https unixpapa.com /js/testkey.html

Code: Select all

#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%

#InstallKeybdHook
#UseHook On

LShift::return
LShift Up::return

z::return
z Up::return
Code with Hotkey command:
Spoiler
I also found the script above works correctly without sending unexpected LShift or z event.

I have been using ahk since 2018 but this is my first post. Thank you for bringing such a great tool. :-D

lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Unexpected keyup event sent by UP hotkeys

Post by lexikos » 05 Jul 2020, 22:28

So what you're saying is that the LShift key-up is not suppressed unless you define the key-down hotkey, even though the key-down is suppressed in both instances?

That does seem to be a bug, but as for whether it's a problem... It's probably gone unnoticed because an isolated key-up almost never has any effect.

mobiusx02
Posts: 2
Joined: 07 Feb 2018, 02:56

Re: Unexpected keyup event sent by UP hotkeys

Post by mobiusx02 » 08 Jul 2020, 04:08

lexikos wrote:
05 Jul 2020, 22:28
So what you're saying is that the LShift key-up is not suppressed unless you define the key-down hotkey, even though the key-down is suppressed in both instances?

That does seem to be a bug, but as for whether it's a problem... It's probably gone unnoticed because an isolated key-up almost never has any effect.
Yes, that is what I'm saying. The bug seems to also apply to all modifier keys.

It probably wouldn't matter if one just wants to disable a key, this can be done with only a keydown hotkey anyway. However, it's problematic if one wants to execute code before actually sending the keyup. Below is an example off the top of my head. It doesn't work because the physical LShift keyup is not suppressed.

Code: Select all

; prolong LShift press by 5 seconds
$LShift Up::
Sleep, 5000
Send {LShift up}
return
I encountered this bug with LWin in a complex situation and spent hours identifying and workaround it. I hope it could be fixed so someone else would save some time.

lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Unexpected keyup event sent by UP hotkeys  Topic is solved

Post by lexikos » 13 Jul 2020, 05:31

Fixed in v1.1.33.01.

TheBeginner
Posts: 91
Joined: 19 Oct 2018, 12:05

Re: Unexpected keyup event sent by UP hotkeys

Post by TheBeginner » 14 Mar 2022, 03:38

I might be mistaken but I think I found a related bug

Code: Select all

a::
	KeyWait, a, T0.30
	send 123-
Return

a UP::
Return

pressing and holding the "a" will cause the 123- to be sent twice, once when key down is fulfilled, and once "a" is released

Code: Select all

a UP::
Return
will not prevent the UP state of the key

Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: Unexpected keyup event sent by UP hotkeys

Post by Hardcoder » 14 Mar 2022, 07:33

TheBeginner wrote:
14 Mar 2022, 03:38
I might be mistaken but I think I found a related bug

Code: Select all

a::
	KeyWait, a, T0.30
	send 123-
Return

a UP::
Return

pressing and holding the "a" will cause the 123- to be sent twice, once when key down is fulfilled, and once "a" is released

Code: Select all

a UP::
Return
will not prevent the UP state of the key
Indeed, this is weird.
Try the following, it writes the addional 123- after the a Up code is done, that is after 1 Second in this case.

Code: Select all

a::
	KeyWait, a, T0.30
	send 123-
Return

a UP::
	SoundBeep
	Sleep, 1000
Return

lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Unexpected keyup event sent by UP hotkeys

Post by lexikos » 09 Apr 2022, 04:55

There's nothing weird about it. If you hold the key down, the a:: hotkey activates roughly every 0.3 seconds because of key-repeat and the T0.30 option (although there may be a delay before this begins, if your key repeat delay exceeds 0.3 seconds). If you release the key, whichever KeyWait is currently running will return early. The empty a UP:: hotkey has nothing to do with it.

If the a UP:: hotkey interrupts KeyWait, the line after KeyWait will not execute until a UP:: returns.
will not prevent the UP state of the key
It isn't supposed to. a:: blocks the key-down event, so the key never enters the (logical) down state in the first place. KeyWait looks at the "physical" state, which is supposed to be unaffected by the hotkeys.

TheBeginner
Posts: 91
Joined: 19 Oct 2018, 12:05

Re: Unexpected keyup event sent by UP hotkeys

Post by TheBeginner » 10 Apr 2022, 03:15

Thanks @Lexicos
had to read like seven times to understand what you're saying :)
If the a UP:: hotkey interrupts KeyWait, the line after KeyWait will not execute until a UP:: returns.
but now I understand why it happened, also I was assuming a UP::Return will block the state as a::Return blocks a key.

Post Reply

Return to “Bug Reports”