Ghost1372

everything can be handy

GlobalKeyboardHook

A Low-Level Global Keyboard Hook runs on a separate thread.

Events

Name
KeyDown
KeyUp
KeyPressed

Methods

Name
Start
Stop
Dispose

Example

1
2
3
4
5
6
7
8
9
10
11
GlobalKeyboardHook hook = new GlobalKeyboardHook();
hook.KeyDown += OnKeyDown;
hook.Start();

private void OnKeyDown(sender s, KeyboardHookEventArgs e)
{
if(e.Key == VirtualKey.B && e.IsCtrl)
{
// Ctrl + B
}
}

Since the GlobalKeyboardHook operates on a different thread, you’ll need to update the UI in the KeyDown/KeyUp/KeyPressed events via a DispatcherQueue. Failing to do so will result in an exception.

Demo

you can run demo and see this feature.

0%