How to assign hotkey of pressing Alt key twice (Alt+Release+Alt) in Autohotkey? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omareg94
Posts: 94
Joined: 27 Jun 2016, 22:46

How to assign hotkey of pressing Alt key twice (Alt+Release+Alt) in Autohotkey?

23 Oct 2018, 10:27

How to assign a hotkey of quickly pressing {Alt} key twice in Autohotkey?

In other words: How to assign Press Alt+Release Alt+Press Alt as a hotkey?
In other words: How to assign key down {Alt} key then key up {Alt} key then quickly key down {Alt}?.

I want to set the time between releasing {Alt} key then pressing it again (to be very small) in order to activate hotkey.
• Example: if the user pressed {Alt} key then released it then waited for 5 seconds then pressed {Alt} key again, the hotkey shouldn't be working or active at all. But if he pressed {Alt} key again before 1.5 seconds, then the hotkey will work. I want to be able to set this time.
• Analogy: it's something like double clicking a mouse button and setting the time between 1st and second click in order for the double-click action to be triggered. But what I'm looking for instead is setting a double click for a keyboard key.
User avatar
Scr1pter
Posts: 1278
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: How to assign hotkey of pressing Alt key twice (Alt+Release+Alt) in Autohotkey?

23 Oct 2018, 10:37

Yes, try something like that:

Code: Select all

LAlt::
profile++
SetTimer check_profile, -800 ; 800 ms limit
return

check_profile:
if (profile = 1)
{
	MsgBox, 1
}
if (profile = 2)
{
	MsgBox, 2
}
if (profile = 3)
{
	MsgBox, 3
}
profile = 0 ; Reset variable
return
Replace the MessageBoxes by useful code

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Rohwedder
Posts: 7737
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to assign hotkey of pressing Alt key twice (Alt+Release+Alt) in Autohotkey?

23 Oct 2018, 11:17

Hallo,
try:

Code: Select all

~LAlt:: ;~ prefix when the hotkey fires, its key's native function will not be blocked
IF !(A_TickCount < LAlt)
{
	KeyWait, LAlt
	LAlt := A_TickCount + 1500 ;1.5 seconds between releasing LAlt then pressing it again
	Return
}
LAlt =
ToolTip, LAlt key twice
Return
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: How to assign hotkey of pressing Alt key twice (Alt+Release+Alt) in Autohotkey?

24 Oct 2018, 04:58

See TapHoldManager
This will allow you to handle multi-tap / long-press etc for any number of keys (ie it supports tap-tap, tap-hold, tap-tap-hold etc)
FYI Rohdwedder's technique will only work for one key. If you try to use the same technique for two keys (eg ALT and CTRL) in the same script, his technique will not work properly if more than one key is held at once (Due to the use of KeyWait).
omareg94
Posts: 94
Joined: 27 Jun 2016, 22:46

Re: How to assign hotkey of pressing Alt key twice (Alt+Release+Alt) in Autohotkey?  Topic is solved

18 Apr 2020, 03:36

Thank you all for your suggestions.
Hope you and all your families are safe.

Sorry for the very late reply.
evilC wrote:
24 Oct 2018, 04:58
See TapHoldManager
This will allow you to handle multi-tap / long-press etc for any number of keys (ie it supports tap-tap, tap-hold, tap-tap-hold etc)
FYI Rohdwedder's technique will only work for one key. If you try to use the same technique for two keys (eg ALT and CTRL) in the same script, his technique will not work properly if more than one key is held at once (Due to the use of KeyWait).
This is the best solution. Thank you a lot.

I have updated your code in order to support Window criteria specification and Pause/Resume/Remove hotkeys (GitHub Pull requests: 1, 2).

Also kindly find the updated code for TapHoldManager.ahk here: (or on GitHub)
Code

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Shikoweno and 145 guests