I use the code below to register hotkeys using C #. But sometimes I get an exception: "I can not register a hot key." What will be the cause of this error? And because they are not consistent. How can I handle this?
public void RegisterHotKey(ModifierKeys modifier, Keys key) { // increment the counter. _currentId = _currentId + 1; // register the hot key. if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key)) throw new InvalidOperationException("Couldn't register the hot key."); }
Reading the MSDN description for RegisterHotKey that I came across:
RegisterHotKey fails if the keys specified for the hotkey are already registered with another hotkey.
Link