简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM