Coder Social home page Coder Social logo

shadowsocks / globalhotkey Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kyrylomyr/globalhotkey

6.0 6.0 21.0 37 KB

Provides an easy way to setup system-wide hot keys and react on their events. Fork here in case something wrong with nuget or upstream repository.

License: GNU General Public License v3.0

C# 100.00%

globalhotkey's Introduction

Global Hot Key

Provides an easy way to setup system-wide hot keys and react on their events. Works well in both, WPF and WebForms applications without any need to use Windows API.

NuGet version Build status

Installation

Th package is available through the NuGet by running the command

PM> Install-Package GlobalHotKey

Usage

An example below demonstrates how to register system-wide hotkey Ctrl+Alt+F5 and handle it:

// Include required namespaces.
using System.Windows.Input;
using GlobalHotKey;

// Create the hotkey manager.
hotKeyManager = new HotKeyManager();

// Register Ctrl+Alt+F5 hotkey. Save this variable somewhere for the further unregistering.
var hotKey = hotKeyManager.Register(Key.F5, ModifierKeys.Control | ModifierKeys.Alt);

// Handle hotkey presses.
hotKeyManager.KeyPressed += HotKeyManagerPressed;

private void HotKeyManagerPressed(object sender, KeyPressedEventArgs e)
{
    if (e.HotKey.Key == Key.F5)
        MessageBox.Show("Hot key pressed!");
}

// Unregister Ctrl+Alt+F5 hotkey.
hotKeyManager.Unregister(hotKey);

// Dispose the hotkey manager.
hotKeyManager.Dispose();

HotKeyManager class registers and unregisters system-wide hotkeys, handles them, and raises an event on hotkeys pressing. KeyPressedEventArgs class contains information about pressed hotkey and keys modifiers. Note, that it is not necessary to unregister all hotkeys manually before closing application, because Dispose() does it. Make sure that it is called.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.