GetKeyState("CapsLock", "P") stopped working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
krl
Posts: 12
Joined: 15 Dec 2019, 05:45

GetKeyState("CapsLock", "P") stopped working

15 May 2024, 03:52

I've been using this script for years. I used it to replace сapslock to left mouse button. Now it has stopped working correctly, instead of a long press, multiple presses are sent.

Code: Select all

#SingleInstance, Force
CapsLock::
	SetKeyDelay 0
	SetMouseDelay 0
	MouseClick, left,,, 1, 0, D
	Loop {
		Sleep, 5
		if !GetKeyState("CapsLock", "P") 
			break
	}
	MouseClick, left,,, 1, 0, U  
	
I looked at the history of the keys, everything looks as usual.
14 03A d 0.31 CapsLock
14 03A d 0.26 CapsLock
14 03A d 0.03 CapsLock
14 03A d 0.03 CapsLock
14 03A d 0.03 CapsLock
14 03A d 0.03 CapsLock
14 03A u 0.03 CapsLock
74 03F d 0.19 F5
74 03F u 0.14 F5
33 004 d 0.94 3
33 004 d 0.25 3
33 004 d 0.03 3
33 004 d 0.03 3
33 004 d 0.03 3
33 004 u 0.01 3


I started researching and found out that GetKeyState now always returns 0. Although for any other key everything works fine.

Code: Select all

#SingleInstance, Force
CapsLock::
3::
    text := GetKeyState(A_ThisHotkey, "P") . " " . GetKeyState(A_ThisHotkey) . " """ . A_ThisHotkey . """"
    OutputDebug % text
return
Output for "CapsLock":
0 0 "CapsLock"

For "3":
0 1 "3"

I can’t yet understand what happened and how to fix it.
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: GetKeyState("CapsLock", "P") stopped working

15 May 2024, 04:02

@krl — We keep having to disapprove duplicate posts of yours. Posts by new members (in terms of number of posts) must be approved before they appear. Please be patient and don’t post the same content again. Thank you.
krl
Posts: 12
Joined: 15 Dec 2019, 05:45

Re: GetKeyState("CapsLock", "P") stopped working

16 May 2024, 04:39

More clear question.
Why now

Code: Select all

3::GetKeyState("3")
returns "1", but

Code: Select all

CapsLock::GetKeyState("CapsLock")
returns "0"
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: GetKeyState("CapsLock", "P") stopped working

16 May 2024, 08:02

Because you're not specifying what you are looking for. CapsLock is one of the keys that has a toggle state. If you want to know its physical state instead of its toggle state, then you need to specify that. The following returns 1:

Code: Select all

CapsLock::MsgBox, % GetKeyState("CapsLock", "P")
krl
Posts: 12
Joined: 15 Dec 2019, 05:45

Re: GetKeyState("CapsLock", "P") stopped working

17 May 2024, 03:54

boiler wrote:
16 May 2024, 08:02
Because you're not specifying what you are looking for. CapsLock is one of the keys that has a toggle state.[/code]
I'm interested in the logical state of the capslock key press. I didn't find in the documentation that capslock doesn't show state logic when it's pressed. Based on this, I thought

Code: Select all

GetKeyState("CapsLock")
should return "1" under normal conditions.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: pgeugene, Rohwedder and 91 guests