0

I'm trying to use AutoHotKey to remap left alt+left shift according to the following conditions:

  • If left alt+ left shift are pressed, wait for both to be released.
  • Then, once both released:
    If the key 1 was pressed with them (i.e., left alt+left shift+1), send 1.
    Else, if the key 2 was pressed with them (i.e., left alt+left shift+2), send 2.
    Else, send 3.

However, I always get 3 sent.

What am I doing wrong?

LAlt & LShift::WaitAndSend()
WaitAndSend() {
  KeyWait, LAlt
  KeyWait, LShift
  if (GetKeyState(1)) {
    Send, 1
  } 
  else if (GetKeyState(2)) {
    Send, 2
  }
  else {
    Send, 3
  }
}
1

The built-in variable A_PriorKey is the name of the last key which was pressed prior to the most recent key-press or key-release in the key history.

LAlt & LShift::WaitAndSend()

WaitAndSend() {
    KeyWait, LAlt
    KeyWait, LShift
    If (A_PriorKey = "1")
        Send, 1
    else If (A_PriorKey = "2")
        Send, 2
    else
        Send, 3
}
| improve this answer | |
  • I'm going to check if it works, but can you please explain (1) why using GetKeyState doesn't result in the required outcome? (2) Also, I can't make sense of using A_PriorKey here: the key press order is lalt, then lshift, then 1 (or 2), thus the most recent key-press is 1 (or 2), and so A_PriorKey should return lshift. What do I miss? – HeyJude May 20 at 9:42
  • GetKeyState works only for left alt+left shift+1 and left alt+left shift+2 if you add KeyWait, 1, L and KeyWait, 2, L. A_PriorKey is the last key pressed before LAlt and LShift are released. – user3419297 May 20 at 10:19
  • Got it, thanks! – HeyJude May 20 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.