Make CapsLock double click? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
firestar9114
Posts: 3
Joined: 19 Apr 2017, 11:46

Make CapsLock double click?

25 Sep 2017, 00:47

So, I constantly hit CapsLock by accident. So I thought it would be nice to make it only work on a double tap. After looking around I thought this solution would work:

Code: Select all

CapsLock:: 
If (A_TimeSincePriorHotkey<200) and (A_PriorHotkey="CapsLock")
{
	if GetKeyState("CapsLock", "T") = 1
 	{
   		SetCapsLockState, off
 	}
	else if GetKeyState("CapsLock", "F") = 0
 	{
   		SetCapsLockState, on
 	}
}
Return
Unfortunately while this mostly implements the intended behaviour I usually activate capslock when I am trying to hit Shift or Tab and I hit capslock by mistake. Fortunately this doesn't enable it, BUT if I hit Shift and mistakenly roll my finger over capslock as well before releasing shift, for some reason CapsLock toggles despite only being pressed once. Why does my code do this, and how can I fix it? (note that holding control and alt instead of shift also cause this behaviour, but not tab, if that helps)
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: Make CapsLock double click?

25 Sep 2017, 08:24

I would guess it is because the script interprets most keys + capslock as an entirely different thing than just capslock, for the purpose of your hotkey. You might try adding * to your hotkey, so it will trigger even if other keys are involved.

Code: Select all

*CapsLock:: 
If (A_TimeSincePriorHotkey<200) and (A_PriorHotkey="CapsLock")
{
	if GetKeyState("CapsLock", "T") = 1
 	{
   		SetCapsLockState, off
 	}
	else if GetKeyState("CapsLock", "F") = 0
 	{
   		SetCapsLockState, on
 	}
}
Return
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Make CapsLock double click?

25 Sep 2017, 08:30

Try

Code: Select all

SetCapslockState OFF

			RETURN	 ; === end of auto-execute section ===

*CapsLock:: ; Fire the hotkey even if extra modifiers are being held down. 
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 300)
{
	KeyWait CapsLock
	If GetKeyState("CapsLock", "T") 
   		SetCapsLockState, off
	else
   		SetCapsLockState, on
}
else
   		SetCapsLockState, off
Return
User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: Make CapsLock double click?

25 Sep 2017, 08:51

A hotkey label is also considered the end of the auto-execute section, so the return is not necessary. :geek:
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
firestar9114
Posts: 3
Joined: 19 Apr 2017, 11:46

Re: Make CapsLock double click?  Topic is solved

25 Sep 2017, 12:10

Thanks for the help, I think that wildcard was the key, after fiddling with it some this solution worked:

Code: Select all

*CapsLock:: ; Fire the hotkey even if extra modifiers are being held down. 
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 300)
{
	If GetKeyState("CapsLock", "T") 
   		SetCapsLockState, off
	else
   		SetCapsLockState, on
}
Return
I removed some extra else statements and things that were making it only require a single click to toggle off. For the sake of consistency I want to have to double click for both activating and deactivating the CapsLock. Thanks for the help. :D

p.s. Also, it appears as though KeyWait isn't needed. I guess that CapsLock doesn't repeat?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot], jomaweb, Rohwedder and 288 guests