3
votes

I want to make an AutoHotKey script where the following things happen, in order when Win+Space is pressed.

  • The next keystroke after Win+Space is recorded
  • If it is g then Google is opened
  • If it is Esc then the computer is locked
  • (Many more conditons like the two above)

I know how to do all of these things except detect the next keystroke after Win+Space.

1

1 Answers

3
votes

You can use the built-in variables A_PriorHotKey and A_TimeSincePriorHotkey to detect the next keystroke after Win+Space and to check whether the hotkey has been pressed recently (otherwise it could activate hours later):

#Space:: return

; The #If directive creates context-sensitive hotkeys:

#If (A_PriorHotKey = "#Space" AND A_TimeSincePriorHotkey < 2000)

    ; If the hotkey was pressed recently (2 seconds)
    ; and g is pressed, then open google:

    g:: Run https://www.google.com ; open google (duh)


#If ; turn of context sensitivity

https://autohotkey.com/docs/commands/_If.htm