This continues to capture keys until the notification keys are released. This can be modified in various ways, to terminate input earlier, to make keys visible, etc.
The script starts to collect keyboard input when the hotkey is triggered. Specific keys are defined as "notification keys". When these keys are released, a function is called. The function looks to see whether two such keys have been released. If so, the input is terminated. This returns flow to the Switch statement in the hotkey subroutine. The Switch statement acts based on the two keys that were released. In this example, only the Alt keys are defined as notification keys, but this could be altered such that additional or even all keys become notification keys.
A reason to use this approach is that you want to use a
sequence of keys, where one or more of the keys in the sequence are not visible (i.e., do not produce text). There are alternative approaches. For example, to look for a small number of keys, one could simply use a couple of
KeyWait commands.
Issues that one could consider may include whether there is a role for any intervening keys, or a role for specific timing or time window during which the key sequence must be completed. This demonstration script proceeds regardless of those factors.
Rohwedder previously posted a script that defines a hotkey for each key of interest. When any of them is pressed, a string concatenates the key names. After a timer expires, the final string is then compared to a key sequence of interest.
Code: Select all
#Requires AutoHotkey v1.1.33.11
ih := InputHook()
ih.KeyOpt("{RAlt}{LAlt}", "N") ; Notification keys (change as needed)
ih.OnKeyUp := Func("ih_KeyUp") ; Releasing any notification key will call this function
Global keys
PrintScreen Up:: ; Initial trigger
ih.Start() ; Start to collect keyboard input
SoundBeep 1500
ih.Wait() ; Wait until input is terminated
Switch { ; Act based on the two released keys
Case keys ~= "[LR]Alt,[LR]Alt" : MsgBox 64, Result, Alt Alt!
Default: SoundBeep 1000 ; Can add more lines if needed
}
Return
ih_KeyUp(ih, VK, SC) { ; Called when a notification key is released
Static str := "", n := 0
str .= (str = "" ? "" : ",") GetKeyName(Format("vk{:x}sc{:x}", VK, SC)) ; List of released keys
n++ ; Number of keys in the list
ToolTip % str
If (n = 2) ; When two notification keys have been released, assign to "keys", stop input
keys := str, str := "", n := 0, ih.Stop()
}
Code: Select all
#Requires AutoHotkey v1.1.33.11
PrintScreen Up::
SoundBeep 1500
KeyWait LAlt, DT1
If !ErrorLevel {
KeyWait LAlt, T1
If !ErrorLevel {
KeyWait LAlt, DT1
If !ErrorLevel
MsgBox
}
}
SoundBeep 2500
Return
Code: Select all
#Requires AutoHotkey v1.1.33.11
Gosub Reset
PrintScreen::
~Alt::
str .= A_ThisHotkey
SetTimer Act, -800
Return
Act:
If (str = "PrintScreen~Alt~Alt")
MsgBox 64, Result, Alt Alt!
Reset:
str := ""
SoundBeep 2500
Return