1

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?

cam
  • 8,725
  • 18
  • 57
  • 81
  • 1
    There 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 Answers3

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 could use this library :

http://www.codeproject.com/KB/system/globalsystemhook.aspx

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
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