This seems straight forward, but I have run into a host of issues. I am using the keyboard hook.
Here is my current iteration of the hotkey that has the fewest bugs. Previous bugs have included either Control not working, the custom function never triggering, or Control or Alt (for some reason I couldn't figure out) being stuck down. Including KeyWait and not specifying the custom function on a RAlt up:: hotkey make things work better, though exactly why I cannot figure out.
All my keys are hot keys, which is why I'm tracking A_ThisHotkey, but the issues are present even if I leave my other scripts off.
Code: Select all
RAlt::{
SendInput("{RControl down}")
if(KeyWait(ThisHotkey, "T0.18")){
KeyWait(ThisHotkey)
SendInput("{RControl up}")
if(ThisHotkey = A_ThisHotkey){
; Custom function
toggleLayer("Numpad")
}
} else {
KeyWait(ThisHotkey)
SendInput("{RControl up}")
}
}
If I hold down RAlt, wait a few seconds, and then press a key (like s to save for example), nothing happens.
Experimenting in VS code I notice that when I hold down RAlt, briefly it behaves as normal, but if I continue to hold it down VSCode's menu becomes highlighted as if I was sending {RAlt down}, but never {RAlt up}. I believe that the code above, for some reason, sends {Control down}, but after the KeyWait times out, sends {RAlt down} instead. That would explain why RAlt & s sends ^s if I press the keys quickly, but not if I wait a few seconds.
I have no idea why this would be though, since I thought the point of a hotkey was to block the native function of the key unless explicitly told otherwise. I've tried variations with GetKeyState, timers, and up hotkeys, but these never seem to work out as I want. I even tried a separate higher input level script that remaps RAlt::Control, but this caused a Lot of issues with stuck down modifiers for some reason.
I do not want to remap the key in the registry, and I don't think that should be necessary given what I'm trying to do should be straightforward. I haven't tried creating a hotkey for every RAlt & key::^key combination, and frankly that seems like overkill. Any advice, suggestions, or even totally different code that accomplishes my core goal is welcome, I am well aware this probably not the most elegant way to implement this. However, it does almost work and the failures are incomprehensible.