" Up::" seems to not work properly in 2.0.7 Topic is solved

Report problems with documented functionality
humanista
Posts: 2
Joined: 03 Nov 2023, 14:44

" Up::" seems to not work properly in 2.0.7

03 Nov 2023, 14:56

I wrote the following code:

Code: Select all

#Warn  ; Recommended for catching common errors.
#SingleInstance force

f20_down := false

#HotIf WinActive("ahk_exe firefox.exe")
F20::
{
	global f20_down
	if(!f20_down)
	{
		Send "{LCtrl down}{RButton down}"
		f20_down := true
	}
	return
}

F20 up::
{
	global f20_down
	Send "{LCtrl up}{RButton up}"
	f20_down := false
	return
}
#HotIf
Nothing fancy, I mapped F20 to one special button in my Logitech mouse using its firmware and then mapped it to left control and right mouse button combo when Firefox is active, so Snap Links add-on can be activated using one button. The "f20_down" global variable is there to suppress context menu popping up when I release the button.

It works as it should in AutoHotkey 2.0.6, but after updating to 2.0.7 and holding the special button down a little longer "F20 up::" is not triggered, so both left control and right mouse button stay down. If I click and release the special button very quickly it's fine. The issue occurs only if I hold it down a bit longer.
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: " Up::" seems to not work properly in 2.0.7

16 Nov 2023, 19:59

This is a result of the following bug fix:
Fixed hook hotkeys not recognizing modifiers which are pressed down by SendInput.
You can work around it by using ^F2 up::, *F2 up::, SendEvent or SendMode "Event".
humanista
Posts: 2
Joined: 03 Nov 2023, 14:44

Re: " Up::" seems to not work properly in 2.0.7

19 Nov 2023, 00:41

*F2 up:: helped, thank you very much!
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: " Up::" seems to not work properly in 2.0.7  Topic is solved

22 Mar 2024, 20:28

I previously suggested that SendEvent could be a workaround, but that was a mistake. When SendEvent is used, or when Send or SendInput falls back to SendEvent mode, the issue you described is present even on v2.0.6 and earlier. SendInput mode was not affected by the issue because of the bug I mentioned above, and the cause of the issue is not related to the bug fix I mentioned.

When we send a {modifier down}, we expect to be able to use this to trigger hotkeys. In other words, putting LCtrl into effect means that we should be able to trigger ^F2::, and conversely, not trigger F2::. So while you are holding F2, key-repeat should not trigger the F2 hotkey; it should execute only the first time, when LCtrl is not in effect. (I'm assuming that the Logitech software emulates key-repeat for F20. I used F2 for testing.)

However, when there is a pair of hotkeys such as F2:: and F2 up:: or ^F2:: and ^F2 up::, we expect the key-up hotkey to execute even if the modifier state does not match. In other words, pressing Ctrl+F2 should trigger ^F2:: and ^F2 up::, even if you release Ctrl before releasing F2; and F2 on its own should trigger F2:: and F2 up:: even if you press Ctrl after pressing F2 before before releasing F2.

The actual issue is that key-repeat was resetting the "hotkey to fire upon release", so the key-up hotkey would only fire if the modifier state matches at the time the key is released, regardless of what it was when the key was pressed. I've decided to consider this a bug, since it isn't consistent with the behaviour prior to key-repeat (or for keys/buttons without key-repeat) and doesn't seem to have any benefit.

Code: Select all

F2::{
	ToolTip A_ThisHotkey
	SendEvent "{LCtrl down}"
}
F2 up::{
	ToolTip A_ThisHotkey
	Send "{LCtrl up}"
}
^F2::{
	ToolTip A_ThisHotkey
	SendEvent "{LCtrl down}"
}
^F2 up::{
	ToolTip A_ThisHotkey
	Send "{LCtrl up}"
}
This demonstrates that ^F2 will execute if you hold the key long enough, then ^F2 up will execute instead of F2 up. Although the behaviour can differ depending on whether the ^F2 hotkeys are defined, in v2.0.11 the F2 up hotkey would not be fired either way. This is fixed by v2.0.12.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 126 guests