making it a prefix key like this:
Code: Select all
d & u:: SendInput '_'
What I've come up is this: send d right away, then introduce an empty loop for 400ms and after the loop (but only if d is still down) check what key is pressed and if u is pressed send _ underscore
However, it seems to bug — when I hold d down I see the counter in the tooltip reaching the 400 threshold, but instead of moving to the other loop it cycles through the first one again, and only then goes for the second loop
Q1: how can I fix it?
Q2: is there a more reliable way to differentiate between a normal keypress during typing and a key combination for such a heavily used key like d
I've also tried to use InputHook to listen for 1 character, but that's inconvenient since once it is activated I can't break it by releasing d, and I'd like to be able to "change my mind" after holding d for longer than 400ms and release it without anything running
Code: Select all
#SingleInstance force
$d::{
threshold := 400
SendInput '{d}'
while (A_TimeSinceThisHotkey<threshold and GetKeyState("d", "P")) { ; 'd' is down < threshold
tooltip(A_TimeSinceThisHotkey)
}
tooltip()
while GetKeyState("d", "P") { ; 'd' is down > threshold
; tooltip(A_PriorKey)
vk_code := Format("vk{:X}",GetKeyVK(A_PriorKey))
if vk_code=="vk44" { ;d self
tooltip(vk_code,,,2)
; continue ; not needed
} else if vk_code == "vk55" { ;u
tooltip(A_TimeSinceThisHotkey,,400,2)
SendInput '{BackSpace}{_}'
break
} else {
break
}
}
tooltip()
Return
}
!r::reload