Advantages of using a hook:GeekDude wrote:@lexikos: What do you think the advantages/disadvantages of scrapping the tons of hotkey commands in favor of an actual keyboard hook would be? As I understand it AHK does some kind of special processing that makes the hotkey commands more reliable across OS, Languages, etc. I'm not sure if this would also apply to my own hook if I run everything through GetKeyName() or similar.
- Reduces the risk of conflicts with other parts of the script using the same hotkeys, or hitting the hotkey limit.
- You can conditionally block the end character and send one less backspace. (Built-in hotstrings do this.)
- Greater accuracy - if done correctly, can handle a wider range of keyboard layouts, including dead keys.
Disadvantages of using a hook:
- Each hook adds a very small amount of latency to the input, and more so for a scripted hook than the built-in hook.
- If the script becomes unresponsive, keyboard input halts until it times out, after which the script will need to be restarted or reinstall its hook.
- Probably more complex (but that's the cost of greater accuracy).
- May reduce the reliability/uninterruptibility of SendInput (but this is irrelevant if you already have multiple running scripts with built-in hooks).
There are some complexities in how hotkeys are recognized, but mostly that doesn't apply to hotstrings. There's not a lot of adaptation for "OS" and "Languages" for hook hotkeys.
Do not use GetKeyName to translate keycodes to characters; use ToUnicodeEx as we previously discussed. Usage is demonstrated (imperfectly) here.