public void InvokeIfMatched(HotKey hotKey, PressType pressType) { if (HotKey == null || hotKey == null || PressType != pressType) { return; } if (hotKey.Equals(HotKey)) { Action?.Invoke(); } }
public void TestStr2HotKey() { Assert.IsTrue(HotKeys.Str2HotKey("Ctrl+A").Equals(new HotKey(Key.A, ModifierKeys.Control))); Assert.IsTrue(HotKeys.Str2HotKey("Ctrl+Alt+A").Equals(new HotKey(Key.A, (ModifierKeys.Control | ModifierKeys.Alt)))); Assert.IsTrue(HotKeys.Str2HotKey("Ctrl+Shift+A").Equals(new HotKey(Key.A, (ModifierKeys.Control | ModifierKeys.Shift)))); Assert.IsTrue(HotKeys.Str2HotKey("Ctrl+Alt+Shift+A").Equals(new HotKey(Key.A, (ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift)))); HotKey testKey0 = HotKeys.Str2HotKey("Ctrl+Alt+Shift+A"); Assert.IsTrue(testKey0 != null && testKey0.Equals(new HotKey(Key.A, (ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift)))); HotKey testKey1 = HotKeys.Str2HotKey("Ctrl+Alt+Shift+F2"); Assert.IsTrue(testKey1 != null && testKey1.Equals(new HotKey(Key.F2, (ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift)))); HotKey testKey2 = HotKeys.Str2HotKey("Ctrl+Shift+Alt+D7"); Assert.IsTrue(testKey2 != null && testKey2.Equals(new HotKey(Key.D7, (ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift)))); HotKey testKey3 = HotKeys.Str2HotKey("Ctrl+Shift+Alt+NumPad7"); Assert.IsTrue(testKey3 != null && testKey3.Equals(new HotKey(Key.NumPad7, (ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift)))); }
internal static void HotkeyPressed(ref MSG m, ref bool handled) { // Only accept hotkey messages if (m.message != WM_HOTKEY || _handlingKeyPress) { return; } // Indicate that we're currently processing a HotKeyPressed event & lock it // Hopefully prevents unknown flooding issue #53 _handlingKeyPress = true; // Find the targeted table, if any Table table = FindTableUnderMouse(); bool wasRelevant = table == null || table.IsVirtual ? false : true; // Handle table related hotkeys HotKey foundHotkey = new HotKey(m.lParam); if (wasRelevant) { if (foundHotkey.Equals(Config.Active.AsideHotKey)) { table.IsAside = !table.IsAside; } // More hotkeys go here } else // if (!wasRelevant) { // Hotkey press was irrelevant for us. Redirect it to foreground window IntPtr foregroundHandle = GetForegroundWindow(); if (foregroundHandle != null) { // Eats some CPU but at least it redirects UnregisterHotKey(foundHotkey); InputSender.RedirectHotkey(foundHotkey); RegisterHotKey(foundHotkey, OurWindowHandle); } } // Unlock the event handler _handlingKeyPress = false; }
public void TestHotKey() { Assert.False(first.Equals(second)); Assert.False(second.Equals(third)); }