It's a simple to use library that allows you to intercept keystrokes or shortcuts in the system.
- Intercept specified keys and shortcuts or intercept every keystroke
- Possibility to "eat" pressed key
- Works on any Windows application platforms (WPF/WinForms/Console)
Add the following string to the .csproj file:
<PackageReference Include="GlobalKeyInterceptor" Version="1.3.0" />Add namespace
using GlobalKeyInterceptor;var interceptor = new KeyInterceptor();
interceptor.ShortcutPressed += (_, e) =>
{
Console.WriteLine(e.Shortcut);
};s_interceptor.RegisterShortcut(new Shortcut(Key.R, state: KeyState.Down), () => Console.WriteLine("R is down"));
s_interceptor.RegisterShortcut(new Shortcut(Key.Alt, KeyModifier.Ctrl), () => Console.WriteLine("Modifier + Modifier as a simple key"));
s_interceptor.RegisterShortcut(new Shortcut(Key.D, KeyModifier.Ctrl | KeyModifier.Alt | KeyModifier.Shift | KeyModifier.Win), () =>
{
Console.WriteLine("Every modifier + D");
// Return true if you want to "eat" the pressed key
return true;
});To allow the console application to intercept keystrokes, you need to add a message loop at the end of the Main() method:
interceptor.RunMessageLoop();Full example you can find here