Skip to content

A simple to use library that allows you to intercept keystrokes or shortcuts in the system.

License

Notifications You must be signed in to change notification settings

arcanexhoax/GlobalKeyInterceptor

Repository files navigation

GlobalKeyInterceptor

NET Version Downloads License

It's a simple to use library that allows you to intercept keystrokes or shortcuts in the system.

Features

  • Intercept specified keys and shortcuts or intercept every keystroke
  • Possibility to "eat" pressed key
  • Works on any Windows application platforms (WPF/WinForms/Console)

Installation

Add the following string to the .csproj file:

<PackageReference Include="GlobalKeyInterceptor" Version="1.3.2" />

Example

Add namespace

using GlobalKeyInterceptor;

Intercept everything

var interceptor = new KeyInterceptor();

interceptor.ShortcutPressed += (_, e) =>
{
    Console.WriteLine($"{e.Shortcut} {e.Shortcut.State}");
};

Intercept only specified keystrokes/shortcuts

interceptor.RegisterShortcut(new Shortcut(Key.R, state: KeyState.Down), () => Console.WriteLine("R is down"));
interceptor.RegisterShortcut(new Shortcut(Key.Alt, KeyModifier.Ctrl), () => Console.WriteLine("Modifier + Modifier as a simple key"));
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;
});

Console application

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

About

A simple to use library that allows you to intercept keystrokes or shortcuts in the system.

Topics

Resources

License

Stars

Watchers

Forks

Languages