Relatively simple solution is to detect the combo directly without blocking the input for these two keys. Once it detects that both keys are pressed, delete the input results by sending backspace
key 2 times, and then run the desired command. This has the benefit that you can still type text without any issues.
OTOH it will work correctly only for the case where current focus is on the text input application/widget and where backspace
means delete last char. In other cases you might get some surprises, e.g. activating random commands.
Here is an example, I used x
and c
keys here. The place where the command fires is the line send {O}
.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
dt := 30 ; milliseconds sleep
k1name := "x" ; key 1
k2name := "c" ; key 2
loop
{
sleep %dt% ; sleep to reduce CPU usage
k1 := getkeystate(k1name, "P") ; get key 1 state
k2 := getkeystate(k2name, "P") ; get key 2 state
if ( ! ( getkeystate("Ctrl", "P") || getkeystate("Alt", "P") || getkeystate("Shift", "P") ) ) {
if ( k1 && k2 && !trig ) {
send {backspace 2}
send {O} ; send some command
trig := 1 ; set flag to avoid repetition
}
if ( !k1 || !k2 ) {
trig := 0
}
}
}
There can be also solutions with overriding the behavior of those keys, but that will be more complicated and has the issues already mentioned in the comments. I personally would tend to stick to the above solution because of its simplicity.