/// <summary> /// Attaches the major hotkey events /// to the Hotkey Listener. /// </summary> private void AttachEvents() { _handle.HotkeyPressed += (s, e) => { HotkeyPressed?.Invoke( new SourceApplication( SourceAttributes.GetID(), SourceAttributes.GetHandle(), SourceAttributes.GetName(), SourceAttributes.GetTitle(), SourceAttributes.GetPath(), SourceAttributes.GetSelection() ), new HotkeyEventArgs { Hotkey = e.Hotkey, SourceApplication = new SourceApplication( SourceAttributes.GetID(), SourceAttributes.GetHandle(), SourceAttributes.GetName(), SourceAttributes.GetTitle(), SourceAttributes.GetPath(), SourceAttributes.GetSelection() ) }); }; }
void ComponentDispatcher_ThreadPreprocessMessage(ref MSG msg, ref bool handled) { if (msg.message == WmHotkey) { HotkeyPressed?.Invoke(); } }
private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { const int WM_HOTKEY = 0x0312; if (msg == WM_HOTKEY) { int id = wParam.ToInt32(); var hotkey = _registeredHotkeys.FirstOrDefault(x => x.Id == id); if (hotkey != null) { if (_requireActiveEveClient && !_windowHelper.IsEveClientActive()) { handled = false; } else { var keyEventArgs = new HotkeyEventArgs(hotkey.Gesture); HotkeyPressed?.Invoke(this, keyEventArgs); handled = keyEventArgs.Handled; } if (!handled) { HotkeyNativeMethods.UnregisterHotKey(_handle, hotkey.Id); KeyboardMessage.Send(hotkey.Gesture); HotkeyNativeMethods.RegisterHotKey(_handle, hotkey.Id, hotkey.Modifiers, hotkey.VirtualKey); } } } return(IntPtr.Zero); }
/// <summary> /// Overrides the default window message processing /// to detect the registered Hotkeys when pressed. /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY) { HotkeyPressed?.Invoke( new SourceApplication( SourceAttributes.GetID(), SourceAttributes.GetHandle(), SourceAttributes.GetName(), SourceAttributes.GetTitle(), SourceAttributes.GetPath(), SourceAttributes.GetSelection()), new HotkeyEventArgs { Hotkey = HotkeyListener.Convert(this.Hotkeys[m.WParam.ToInt32()]), SourceApplication = new SourceApplication( SourceAttributes.GetID(), SourceAttributes.GetHandle(), SourceAttributes.GetName(), SourceAttributes.GetTitle(), SourceAttributes.GetPath(), SourceAttributes.GetSelection()) }); } else { base.WndProc(ref m); } }
public void HandleKeyDown(object sender, KeyEventArgs e) { foreach (KeyEventArgs key in Hotkeys) { if (key.Modifiers == e.Modifiers && key.KeyCode == e.KeyCode) { HotkeyPressed?.Invoke(sender, e); } } if (!e.Handled) { switch (e.KeyCode) { case Keys.F11: if (ToggleFullScreenRequest != null) { ToggleFullScreenRequest(sender, e); e.Handled = true; } break; } } if (!e.Handled) { switch (EchoMode) { case EchoModes.LineEdit: break; case EchoModes.FullScreenEdit: e.Handled = HandleEditKey(e); break; case EchoModes.Plugin: e.Handled = true; Editor?.HandleKeyDown(sender, e); break; case EchoModes.EchoOff: case EchoModes.LocalEcho: default: if (e.KeyCode == Keys.F12) { EchoMode = EchoModes.FullScreenEdit; InsertMode = InsertKeyMode.Overwrite; BlinkCursor(); e.Handled = true; } break; } } if (!e.Handled) { TerminalKeyEventArgs k = new TerminalKeyEventArgs(e); Terminal.SendKey(k); } }
private void OnKeyPressed(object sender, IKeyTrackerEventArgs e) { if (_combosEnumerator.Current.IsPressed(_keyTracker.Modifiers, e.Key)) { if (_combosEnumerator.MoveNext()) { return; } ResetEnumerator(); var args = new HotkeyEventArgs { Handled = Handled }; _pressedKeys = _keyTracker.GetPressedKeysSet(); IsPressed = true; HotkeyPressed?.Invoke(this, args); e.Handled = args.Handled; } else if (!e.IsModifier) { IsPressed = false; ResetEnumerator(); } }
public int RegisterHotkey(Modifiers modifier, Keys key, Window window, HotkeyPressed evt) { if (_hWnd == null) { _hWnd = new WindowInteropHelper(window).Handle; } var src = PresentationSource.FromVisual(window) as HwndSource; if (src == null) { throw new Exception("Can't create hWnd source from window"); } if (_hWnd == null) { throw new Exception("hwnd null"); } src.AddHook(WndProc); int id = ((int)modifier ^ (int)key ^ _hWnd.ToInt32()) * 555; if (!RegisterHotKey(_hWnd, id, (int)modifier, (int)key)) { throw new Exception("Can't register hotkey >:("); } keys.Add(id, new DataContainer(modifier, key, evt)); return(id); }
protected virtual void OnHotkeyPressed(EventArgs e) { if (hotkeySuspendCount < 1) { HotkeyPressed?.Invoke(this, e); } }
private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_SYSKEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); switch ((Keys)vkCode) { case Keys.F1: case Keys.F2: case Keys.F3: hotkeyEvent = new HotkeyEventArgs((Keys)vkCode); HotkeyPressed?.Invoke(hotkeyEvent); break; default: break; } if (SettingsManager.Settings.ActivateKey == (Keys)vkCode) { activedEvent = new ActivatedEventArgs(); Activated?.Invoke(activedEvent); // Processed the message so return nonzero value to prevent passing value to the rest of the hook chain. return(IntPtr.Add(IntPtr.Zero, 1)); } } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
protected virtual void OnHotkeyPressed( Keys key, ModifierKeys modifierKeys) => HotkeyPressed?.Invoke(this, new HotkeyPressedEventArgs { PressedKey = key, ModifierKeys = modifierKeys, });
public void ProcessHotkey(int Id) { var hotkey = Hotkeys.SingleOrDefault(H => H.Id == Id); if (hotkey != null) { HotkeyPressed?.Invoke(hotkey.Service.ServiceName); } }
/// <summary> /// Attaches the major hotkey events to the Hotkey Listener. /// </summary> private void AttachEvents() { _handle.HotkeyPressed += (s, e) => { HotkeyPressed?.Invoke(null, new HotkeyEventArgs { Hotkey = e.Hotkey }); }; }
protected override void WndProc(ref Message m) { const int WM_HOTKEY = 0x312; if (m.Msg == WM_HOTKEY) { if (_hotkeyID.ContainsKey(m.WParam.ToInt32())) { HotkeyPressed?.Invoke(this, _hotkeyID[m.WParam.ToInt32()].KeyEvent); } return; } base.WndProc(ref m); }
private void OnWindowHotkeyMessage(int lParam) { //"The low-order word specifies the keys that were to be pressed //in combination with the key specified by the high-order word to generate the WM_HOTKEY message. //The high-order word specifies the virtual key code of the hot key." int low = lParam & 0xFF; //modifier key int high = lParam >> 16; //key var hotkey = new HotKey(KeyInterop.KeyFromVirtualKey(high), (ModifierKeys)low); if (RegisteredHotkeys.ContainsKey(hotkey)) { HotkeyPressed?.Invoke(hotkey); } }
/// <summary> /// Overrides the default window message processing to detect the registered Hotkeys when pressed. /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY) { var hotkey = HotkeyRepresentation.AsHotkey(this.Hotkeys[m.WParam.ToInt32()]); HotkeyPressed?.Invoke(null, new HotkeyEventArgs { Hotkey = hotkey }); } else { base.WndProc(ref m); } }
private void DetectHotkeyInput() { if (HotkeyPressed == null) { return; } for (int i = 0; i < 9; i++) { if (Input.GetKeyDown(KeyCode.Alpha1 + i)) { HotkeyPressed?.Invoke(i); } } }
protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_HOTKEY: HotkeyPressed?.Invoke(m.WParam.ToInt32()); break; case WM_DESTROY: // fires when "Application.Exit();" is called foreach (var id in ids) { UnregisterHotKey(Handle, id); } break; } base.WndProc(ref m); }
protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_HOTKEY: //raise the HotkeyPressed event HotkeyPressed?.Invoke(m.WParam.ToInt32()); break; case WM_DESTROY: //unregister all hot keys foreach (int ID in IDs) { UnregisterHotKey(this.Handle, ID); } break; } base.WndProc(ref m); }
private void OnHotkeyPressed(object sender, HotkeyPressedEventArgs e) { var key = e.Key; var modifiers = e.Modifier; var hotkeys = _hotkeys; for (int i = 0; i < hotkeys.Count; i++) { var entry = hotkeys[i]; if (entry.Key == key && entry.Modifiers == modifiers) { HotkeyPressed?.Invoke(this, entry.Id); return; } } }
public DataContainer(Modifiers m, Keys k, HotkeyPressed e) { modifier = m; key = k; evt = e; }
private void OnHotkeyPressed(object sender, HotkeyEventArgs e) { HotkeyPressed?.Invoke(sender, EventArgs.Empty); }
public void FakeHotkey(ServiceName Service) { HotkeyPressed?.Invoke(Service); }
public int RegisterHotkey(Modifiers modifier, Keys key, Window window, HotkeyPressed evt) { if (_hWnd == null) _hWnd = new WindowInteropHelper(window).Handle; var src = PresentationSource.FromVisual(window) as HwndSource; if (src == null) throw new Exception("Can't create hWnd source from window"); if (_hWnd == null) throw new Exception("hwnd null"); src.AddHook(WndProc); int id = ((int) modifier ^ (int) key ^ _hWnd.ToInt32()) * 555; if (!RegisterHotKey(_hWnd, id, (int) modifier, (int) key)) throw new Exception("Can't register hotkey >:("); keys.Add(id, new DataContainer(modifier, key, evt)); return id; }
private void KeyPressed(ushort id, Keys key, Modifiers mods) { HotkeyPressed?.Invoke(null, new HotkeyEventArgs(id, key, mods)); }
protected virtual void OnHotkeyPressed(KeyEventArgs e) { HotkeyPressed?.Invoke(this, e); }