0
votes

I am using .ahk for some days now and it is cool to work with. I try to say that if CapsLock is activated my code runs / or not. This code below checks if CapsLock is pressed down in this moment (working).

GetKeyState, CapLck, CapsLock, P
if ( CapLck == "D" ) {
some statement
}

I would like to change that if I click CapsLock once its activated - when I press it again it deactivates.

My research found out, that the parameter P in GetKeyState, CapLck, CapsLock, P checks if CapsLock is physically clicked down at this moment. If this is true it gives back the D which is used to check in the if-statement below.

So I tried changing the code from

GetKeyState, CapLck, CapsLock, P
if ( CapLck == "D" ) {
some statement
}

to this

GetKeyState, CapLck, CapsLock, T
if ( CapLck == 1 ) {
some statement
}

If I read the GetKeyState documentation right the parameter T checks if CapsLock is activated or not. If activated it gives back 1 for true; 0 for false.

Sadly my changes do not apply and it does not work. Any ideas?

Thanks.

2

2 Answers

0
votes

Try this:

#If GetKeyState("CapsLock", "T") ; If Capslock is On
    a::MsgBox % "CAPSLOCK IS ON"
#If

a::MsgBox % "CAPSLOCK IS OFF"
0
votes

In order to check if CapsLock is activated or not simply change

GetKeyState, CapLck, CapsLock, P
if ( CapLck == "D" ) {
some statement
}

to

GetKeyState, CapLck, CapsLock, T
if ( CapLck == "D" ) {
some statement
}

In contrast to the AutoHotKey documentation the parameter T gives back "D" for true not 1.