0
votes

In the following script,when I press the CapsLock and Alt keys and then the J key,"is work" message will not pop up. Only by simultaneously pressing the CapsLock, Alt, and J keys and immediately releasing the keys will "it work" message pop up.

CapsLock & J::
if GetKeyState("Alt","p"){
    MsgBox  is work
}
return

Change the key J to K, as follows:

CapsLock & K::
if GetKeyState("Alt","p"){
    MsgBox  is work
}
return

This allows you to press the CapsLock and Alt keys first and then the K key to pop up the "it work" message. I tried other keys, such as A, S, D, F, H, and so on.But you can't change it to G. Only three keys can be pressed at the same time and immediately release the normal output "is work"

I don't understand why?

When custom key combinations use GetKeyState, what is the order in which the keys are executed?

1

1 Answers

0
votes

As soon as you trigger your hotkey by pressing CapsLock + J or K it's looking to see if Alt is pressed. So if there is any delay between when the hotkey is triggered and Alt is pressed, then your MsgBox won't show.

To get it to work every time, start by holding the key that GetKeyState is looking for (Alt) and then hold your other keys in order from left to right as listed. So, hold Alt, then hold CapsLock, then press J or K.