Change func for both single and double press Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
akaza_dorian
Posts: 9
Joined: 30 Nov 2019, 15:44

Change func for both single and double press

Post by akaza_dorian » 07 Apr 2020, 10:46

I'm trying to make the CapsLock key macOS like, and here's the code:

Code: Select all

CapsLock::
    If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 200) {
        SetCapsLockState % !GetKeyState("CapsLock", "T") 
    } else { ; needs tweak, now it will be triggered on double press
        Send, ^#{Space}
    }
Return
The problem is even if I double press CapsLock, the first press will be recognized as a single press, is there a way to get rid of it?
What I am expecting is for single pressing CapsLock, send ctrl + win + space instead, for double pressing, change CapsLock state.

Rohwedder
Posts: 7768
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Change func for both single and double press  Topic is solved

Post by Rohwedder » 07 Apr 2020, 11:44

Hallo,
try:

Code: Select all

CapsLock::
If !T := 0 T + 1
    SetTimer, T, -400
Return
T:
IF !T ;single
	 Send, ^#{Space}
Else ;double
	SetCapsLockState,% !GetKeyState("CapsLock", "T")
T =	
Return

akaza_dorian
Posts: 9
Joined: 30 Nov 2019, 15:44

Re: Change func for both single and double press

Post by akaza_dorian » 07 Apr 2020, 13:59

@Rohwedder You answer works perfectly! Thank you!

Post Reply

Return to “Ask for Help (v1)”