Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if Hotkey combination already exists

Tags:

c#

I am using Registerhotkey to allow my users to define custom key combinations to perform different actions. The problem I seem to be having is that there is currently no way to check if the key already exists.

For example: One of my testers tried to define "Windows Key + D" not knowing that is the key combination to minimize all windows. So I was curious if there was any way to tell if given a key combination that I could check if that key combination already exists by windows or any other application.

like image 997
Robert E. McIntosh Avatar asked Jan 21 '26 11:01

Robert E. McIntosh


1 Answers

Thanks to @jim-mischel for helping me find this solution!

To check if a hot key exists simply do the following:

int ShortcutID = 100; // ID used for this Shortcut Key Combination
uint keyModifier = 2; // This is the Control Key
Char alphanumericKey = "C";
bool didItError
   = RegisterHotKey(this.Handle, ShortcutID, keyModifier, (int)alphanumericKey );

Since Control+C is a registered key combination by windows the RegisterHotKey will return false, if it was not a registered key combination it would return true!

like image 131
Robert E. McIntosh Avatar answered Jan 27 '26 02:01

Robert E. McIntosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!