I used to use the RegisterHotkey
method but users have had issues based on their keyboard. For example, the hotkey does not work while a command prompt is focused. Or if the ctrl+alt+del dialog is focused. The LowLevelKeyboardHook
worked uniformly across all users.
I had an issue though with modifiers. For instance if the hotkey is Win+F. If the user first:
- downs the Win, I allow it
- then downs the F key, I block it
- if user ups the F key then I block it too
- however, on up of the Win key, it comes through and the start menu opens
I tried blocking the Win key on step 4. However this causes it stays depressed in the keyboard buffer (pressing L for instance will lock the computer).
Is there a way to clear the keyboard buffer?
I was thinking of blocking the up, but after all keys are released, then clear the buffer.
I tried the method from this SO answer, but it didn't work:
#include <conio.h>
while (_kbhit()) {
_getche();
}