Git Product home page Git Product logo

hotkeys's Introduction

Hotkeys

A small C# (.NET) Library which allows binding of global HotKeys to any Application's Windows (including Windows Apps such as explorer.exe), even in Background. (using P/Invokes)

Install

Install from NuGet

Install-Package GlobalHotkeys

NuGet

(or download the Library (.dll) manually)

Buy Me a Coffee at ko-fi.com

Usage

Example (C#, in a WPF Application):

using mrousavy;
// ...
var key = new HotKey(
    (ModifierKeys.Control | ModifierKeys.Alt), 
    Key.S, 
    this, 
    (hotkey) => {
        MessageBox.Show("Ctrl + Alt + S was pressed!");
    }
);
// ...
key.Dispose();

Note #1: Since HotKey implements the IDisposable interface, you must call Dispose() to unregister the Hotkey, e.g. when your Window closes. Keep in mind that when you're using using(...) { ... }, the HotKey gets unregistered and disposed once you exit the using-statement's scope.

Note #2: Use the binary or operator (|) to combine key combinations for the constructor.

Note #3: Use a Window Reference as the third Argument. This may be a WPF Window, a WindowInteropHelper, or a Window Handle (IntPtr). So you can use your own WPF/WinForms Window, as well as another process's Window using it's Handle. Keep in mind that this is sketchy behaviour and not the intention of this library.

hotkeys's People

Contributors

mrousavy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hotkeys's Issues

Any hotkeys seem already occupied

No matter which hotkey combination I try, the Contructor throws me an exception that the hotkeys may already be occupied.

System.ApplicationException
  HResult=0x80131600
  Nachricht = An unexpected Error occured! (Hotkey may already be in use)
  Quelle = Hotkeys
  Stapelüberwachung:
   bei mrousavy.HotKey.RegisterHotKey()
   bei mrousavy.HotKey..ctor(ModifierKeys modifierKeys, Key key, IntPtr windowHandle, Action`1 onKeyAction)
   bei mrousavy.HotKey..ctor(ModifierKeys modifierKeys, Key key, Window window, Action`1 onKeyAction)
   bei WpfApp1.MainWindow..ctor() in C:\Users\Dominik\source\repos\UeliSharp\WpfApp1\MainWindow.xaml.cs: Zeile28

problems with delegate

I tried to add a function to the delegate of your example like this

delegate{
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(A, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(A, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);
}

does not get correct result. why?

I did not use the messagebox in the example. Is that nescessary?

a bug(I do not know whether this is bug actually)

Recently I am exploring how to use this package(dll) with InputSimulator.
I found out that every time I use [new Hotkey ] to monitor hot keys, I have to add a Thread.sleep(100) to insure that the monitored hot key combo is released.
For example:
var key = new HotKey(
(ModifierKeys.Control | ModifierKeys.Alt),
Key.S,
this,
() => {
Inputsimulator...
Inputsimulator...
}
);
This will not generate correct result.
I have to write like this:
var key = new HotKey(
(ModifierKeys.Control | ModifierKeys.Alt),
Key.S,
this,
() => {
Thread.sleep(100)
Inputsimulator...
Inputsimulator...
}
);
This will get the correct result. (Only in this way can the shift+s get released before Inputsimulator is used.)

new problem

Hi i am using the example you provided and tried to invoke ctrl+w when i press ctrl+alt+s,but it turns out to be buggy...

suggestion to author

You really should tell the users to add "using mrousavy" in their code...
This is my solution to my problem, but I nearly took an hour to find it out...

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.