Giter Site home page Giter Site logo

shortcut's Introduction

#Shortcut

Shortcut enables you to quickly and easily bind system-wide hotkeys to callbacks so that when the system-wide hotkey in question is pressed, the bound callback will be invoked.

Shortcut is built in such a way that you can bind system-wide hotkeys with the following succinct and expressive syntax:

_hotkeyBinder.Bind(Modifiers.Control, Keys.A).To(() => 
    MessageBox.Show("You pressed Control + A.");

##Installation

Shortcut is available to build from source or to download manually, but for convenience is available on NuGet:

Install-Package Shortcut

##Getting Started

public partial class MainForm : Form 
{
    // Declare and instantiate the HotkeyBinder.
    private readonly HotkeyBinder _hotkeyBinder = new HotkeyBinder();
    
    // Declare the callback that you would like Shortcut to invoke when 
    // the specified system-wide hotkey is pressed.
    private static void HotkeyCallback() 
    {
        MessageBox.Show("You pressed Control + A.");
    }
    
    public MainForm() 
    {
        // Tell Shortcut to bind a specified system-wide hotkey to the
        // callback you declared earlier. 
        _hotkeyBinder.Bind(Modifiers.Control, Keys.A).To(HotkeyCallback);

        // Alternative syntax.
        // var hotkey = new Hotkey(Modiiers.Control, Keys.A); 
        // _hotkeyBinder.Bind(hotkey).To(HotkeyCallback);
    }
}

If you want a tangible example or to see Shortcut within the context of another UI framework, please see one of the many demos.

##GUI

Shortcut 2 introduced some custom controls for Windows Forms projects. One such control is the HotkeyTextBox which enables users to intuitively input a hotkey combination:

(Screenshot is of Ember which incidentally, is a good example of Shortcut in practice.)

Before you can access this custom HotkeyTextBox control, you will need to manually add a reference to Shortcut.dll to your Toolbox. To do this:

  1. Install Shortcut
  2. Locate Shortcut.dll in your bin/ folder.
  3. Drag and drop Shortcut.dll on to the Toolbox.

you should now see the HotkeyTextBox control in your Toolbox. You can set or get the control's value via the its Hotkey property.

Misc

Shortcut does expose that many public methods however, all of those that it does are documented using XML comments. You should be able to ascertain the purpose of each method from it's name and it's accompanying documentation (visible via Intellisense).


Use the HotkeyBinder.IsHotkeyAlreadyBound to determine whether a system wide hotkey has already been bound either by your application.

If you want to register a system-wide hotkey comprised of more than one modifiers (for example, Ctrl, Alt + A), do this:

var hotkeyCombination = new HotkeyCombination(Modifiers.Control | Modifiers.Alt, Keys.F);

shortcut's People

Watchers

 avatar  avatar

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.