NESHOM
NESHOM

Reputation: 929

Multiple global hotkeys in C# console application

To register global hotkey in console application in C#, I am using the code posted here: https://stackoverflow.com/a/3654821/3179989

It works perfectly, but when I add multiple hotkeys, pressing one hotkey will result in running all of the hotkey_pressed events:

   HotKeyManager.RegisterHotKey(Keys.E, KeyModifiers.Control);
   HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed);

   HotKeyManager.RegisterHotKey(Keys.A, KeyModifiers.Control);
   HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed2);

Can somebody help me to change the code, or suggest me any other solution/idea for multiple global hotkeys in c# console.

thanks in advance

Upvotes: 1

Views: 1716

Answers (1)

user1567896
user1567896

Reputation: 2398

This will not work with the class you are using.

Only register one HotKeyPressed-Event. In this event you can check the HotKeyEventArgs with a simple if-statement to determine which of your hotkeys was pressed.

Upvotes: 1

Related Questions