Issue with key hold down Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Issue with key hold down

Post by fona » 25 May 2022, 09:26

Hi everyone,
When the hotkey Alt + Left is held down it closes the active tab in Firefox. However, if the hotkey Alt + Left is held down more than 0.20 seconds it closes also other tabs, which I really don't like. I just want it to execute only once and stop. Is it possible to prevent the routine?

Code: Select all

~!Left::
		KeyWait, !, T0.20 ;Check if mouse button get's released immediately
		KeyWait, Left, T0.20 ;Check if mouse button get's released immediately
		if (ErrorLevel = 1){ ; Button is still down
			Sendinput ^w
		}
return

User avatar
mikeyww
Posts: 26951
Joined: 09 Sep 2014, 18:38

Re: Issue with key hold down  Topic is solved

Post by mikeyww » 25 May 2022, 09:28

You can add another KeyWait as the last line of your hotkey routine.

KeyWait can use a key name such as Alt where needed. See https://www.autohotkey.com/docs/KeyList.htm#modifier

It is a single key from the key list or keyboard itself (not a modifier used as a modifer).

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: Issue with key hold down

Post by fona » 25 May 2022, 09:42

mikeyww wrote:
25 May 2022, 09:28
You can add another KeyWait as the last line of your hotkey routine.

KeyWait can use a key name such as Alt where needed. See https://www.autohotkey.com/docs/KeyList.htm#modifier

It is a single key from the key list or keyboard itself (not a modifier used as a modifer).
Is that correct? Or you meant something different?

Code: Select all

~!Left::
		KeyWait, Alt, T0.20 ;Check if mouse button get's released immediately
		KeyWait, Left, T0.20 ;Check if mouse button get's released immediately
		
		if (ErrorLevel = 1){ ; Button is still down
			Sendinput ^w
		}
		KeyWait, Left, T7 ;Check if mouse button get's released immediately
return

User avatar
mikeyww
Posts: 26951
Joined: 09 Sep 2014, 18:38

Re: Issue with key hold down

Post by mikeyww » 25 May 2022, 10:16

It looks OK.

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: Issue with key hold down

Post by fona » 25 May 2022, 10:28

mikeyww wrote:
25 May 2022, 10:16
It looks OK.
Yes, It works fine. Thank you!

User avatar
mikeyww
Posts: 26951
Joined: 09 Sep 2014, 18:38

Re: Issue with key hold down

Post by mikeyww » 25 May 2022, 10:30

It's unusual to have two KeyWait commands consecutively when both have timeouts. I'm not sure that it helps you much here, since you do not check the ErrorLevel for the first KeyWait. Note, too, that the ErrorLevel pertains only to the immediately preceding command in this case. Most users would release the non-modifier key (e.g., Left) first, rather than the modifier key.

Post Reply

Return to “Ask for Help (v1)”