Issue with GetKeyState in Windows 11

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rafio
Posts: 41
Joined: 07 Oct 2018, 05:14

Issue with GetKeyState in Windows 11

Post by Rafio » 28 Nov 2022, 07:14

This snippet of code that used to work in W7 or W10 (don't remember which one) is no more able to get the state of capslock key.
The original script is a collection of functions that let me import textes and images in a Publisher doc from another document in Word or Publisher.
Capslockstate is a good way to use the same hotkey, telling the script what source to use.

The first 3 lines are in the original script.
I tried to add #InstallKeybdHook, several combinations of #If or If and other subtleties but got no success.

Where is my mistake?

Code: Select all

#SingleInstance Force
#NoEnv
SendMode Input


F18::
If (GetKeyState("CapsLock", "T")) OR (WinActive("ahk_class OpusApp")) {
	MsgBox readingPOSWRD(1)
	Return
} else {
	MsgBox readingPOSPUB(1)
	Return
}

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

Re: Issue with GetKeyState in Windows 11

Post by mikeyww » 28 Nov 2022, 07:31

Hi,

1. Try a one-line script-- no other code-- to test your idea.

Code: Select all

F3::MsgBox, 64, CapsLock toggle state, % GetKeyState("CapsLock", "T")
2. Report your AutoHotkey version, and whether the script posted above worked.

3.
No more able to get the state of capslock key
How did you determine that?

Rafio
Posts: 41
Joined: 07 Oct 2018, 05:14

Re: Issue with GetKeyState in Windows 11

Post by Rafio » 28 Nov 2022, 08:09

Bonjour.

1. Your script always return 0. No matter the state of capslock key.

2. AHK version is 1.1.35.00. Windows 11 is French localized.

3. With all the tests I made. Your script is confirming all my attempts.
--
Windows 11
AHK 1.1.35.00
Adventure 3.0.4

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

Re: Issue with GetKeyState in Windows 11

Post by mikeyww » 28 Nov 2022, 08:49

When you type letters in this state, are you seeing them appear in all caps?

Rafio
Posts: 41
Joined: 07 Oct 2018, 05:14

Re: Issue with GetKeyState in Windows 11

Post by Rafio » 28 Nov 2022, 09:02

Yes. Letters are in capitals and there's a green light on my keyboard.

I've made another test:
In the first script I posted here, If I replace CapsLock with NumLock, the script runs as expected.
If I make the same replacement in your script, the dialog reflects the real state of the key.

In short, NumLock works, CapsLock don't.
Could the cause of this problem be a localization issue?
--
Windows 11
AHK 1.1.35.00
Adventure 3.0.4

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

Re: Issue with GetKeyState in Windows 11

Post by mikeyww » 28 Nov 2022, 09:04

I have not seen that with CapsLock previously; seems odd. I tested my script on Win 11 with US keyboard, and it worked as expected. Others can chime in here with additional ideas & suggestions. If I were in your position, I would try a different keyboard to see what happens, and ensure that all other keyboard utilities, AHK scripts, and macro programs are closed.

Post Reply

Return to “Ask for Help (v1)”