I'm using SetWindowsHookEx to capture the keyboard in order to show a running application. I can create combinations using CTRL, ALT, SHIFT, and regular keys. However I can't create a combination using the WINDOWS key (for example, CTRL + WINDOWS + A).
I've seen articles about capturing the WINDOWS key in isolation (such as to prevent the Windows 8 start screen when a game is running), but never to create a combination.
I know it's possible to capture these combinations as software such as AutoHotKey does it.
Is SetWindowsHookEx the wrong way to do this?
I found a similar question that contained an answer that assisted. This led me down the right path to a solution.
It appears Keyboard.Modifiers can't detect the Windows key (at least on my Win8 instance).
Instead, I had to handle the Windows key in a different way using
Keyboard.IsKeyDown
. This led to build a method to check whether the combination of a key pressed (from my LowLevelKeyboardProc) and the current modifier keys being pressed is the same as the defined key and modifiers in propertiesHotKey
andHotKeyModifiers
.Here's the C# of the LowLevelKeyboardProc:
And the C# for the IsKeyCombinationPressed() method: