Search code examples
c#keyboard-hook

How do I create a keyboard hook with a different thread in C#?


I'm creating a low level keyboard hook in c# using SetWindowsHookEx, question is how can I make the on keyboard event function run on a thread other from the main thread? Also I currently don't have a thread other then the main thread, so how can I create one that will halt until a keyboard hook event will occur?


Solution

  • Here is the code for the C# Keyboard hook.

    You just need to call Hook.CreateHook(METHODNAMEHERE); in a new Thread (see the Thread class).