I would like to run a low-level keyhook on a seperate thread in C# to detect for certain hotkeys. How would I do this?
Asked
Active
Viewed 2,331 times
1
-
1There are many questions and answers on this topic here on SO. A very complete example : http://stackoverflow.com/questions/1639331/using-global-keyboard-hook-whkeyboardll-in-wpf-c Suggest you search on "GetAsyncKeyState" as well as "global hook," "keyboard hook," "lower-level keyboard hook," etc. – BillW Feb 03 '10 at 12:32
3 Answers
3
If you need this keyboard hook only to detect hot keys then you should not use a hook. Windows supports hot keys with the RegisterHotKey() API function. Check my code sample in this thread to see how to use it. There's a C# sample further down the page.

Hans Passant
- 922,412
- 146
- 1,693
- 2,536
1
You can to use DirectX. Add a reference to Microsoft.DirectX.DirectInput (after you've installed directX on your machine. Here is the SDK.)
Create an instance of the device class:
keyboard = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
And you can now listen to the keyboard.

sagie
- 2,998
- 3
- 22
- 31