public bool Register(IntPtr windowControl)
{
// Check that we have not registered
if (this.registered)
{
throw new NotSupportedException("You cannot register a hotkey that is already registered");
}
// We can't register an empty hotkey
if (this.Empty)
{
throw new NotSupportedException("You cannot register an empty hotkey");
}
// Get an ID for the hotkey and increase current ID
this.id = Hotkey.currentID;
Hotkey.currentID = Hotkey.currentID + 1 % Hotkey.maximumID;
// Translate modifier keys into unmanaged version
uint modifiers = (this.Alt ? Hotkey.MOD_ALT : 0) | (this.Control ? Hotkey.MOD_CONTROL : 0) |
(this.Shift ? Hotkey.MOD_SHIFT : 0) | (this.Windows ? Hotkey.MOD_WIN : 0);
// Register the hotkey
if (Hotkey.RegisterHotKey(windowControl, this.id, modifiers, keyCode) == 0)
{
// Is the error that the hotkey is registered?
if (Marshal.GetLastWin32Error() == ERROR_HOTKEY_ALREADY_REGISTERED)
{
return(false);
}
else
{
throw new Win32Exception();
}
}
// Save the control reference and register state
this.registered = true;
//this.windowControl = windowControl;
// We successfully registered
return(true);
}