public void KeyHook_KeyUp(object sender) { HotkeyCtrl hotkeyCtrl = (sender as HotkeyCtrl); Hotkey hotkey = FindHotkey(hotkeyCtrl); LoadProfile(hotkey.profileName); }
public Hotkey FindHotkey(HotkeyCtrl ctrl) { foreach (Hotkey hotkey in Hotkeys) { if (hotkey.hotkeyCtrl == ctrl) { return(hotkey); } } return(null); }
public void Unregister() { // Check that we have registered if (!this.registered) { throw new NotSupportedException("You cannot unregister a hotkey that is not registered"); } // It's possible that the control itself has died: in that case, no need to unregister! if (!this.windowControl.IsDisposed) { // Clean up after ourselves if (HotkeyCtrl.UnregisterHotKey(this.windowControl.Handle, this.id) == 0) { //throw new Win32Exception(); } } // Clear the control reference and register state this.registered = false; this.windowControl = null; }
public bool Register(Control windowControl, Hotkey hotkey) { // Check that we have not registered if (this.registered) { throw new NotSupportedException("You cannot register a hotkey that is already registered"); } // Get an ID for the hotkey and increase current ID this.id = HotkeyCtrl.currentID; HotkeyCtrl.currentID = HotkeyCtrl.currentID + 1 % HotkeyCtrl.maximumID; // Translate modifier keys into unmanaged version uint modifiers = (hotkey.Alt ? MOD_ALT : 0) | (hotkey.Ctrl ? MOD_CONTROL : 0) | (hotkey.Shift ? MOD_SHIFT : 0) /*| (hotkey.Windows ? MOD_WIN : 0)*/; // Register the hotkey if (HotkeyCtrl.RegisterHotKey(windowControl.Handle, this.id, modifiers, hotkey.Key) == 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); }
public Hotkey() { hotkeyCtrl = new HotkeyCtrl(); RemoveKey = false; }