/// <summary> /// Handles key down events, dispatching events for both hotkeys and unhandled key presses. /// </summary> private void OnKeyDown(object sender, KeyEventArgs e) { var key = e.KeyCode; // Reset display sleep timer _powerManager.ResetTimer(); if (_settings.HotKeys && _keyMapping.ContainsKey(key)) { var hotKey = _keyMapping[key]; Log.Debug("Hotkey {hotkey} pressed", hotKey); // Unsubscribe to key events if the user is playing the game as control is shifted to MAME if (hotKey == HotKey.PlayGame) { _activityHook.KeyDown -= OnKeyDown; } // Publish hotkey event HotKeyPressed?.Invoke(sender, new HotKeyEventArgs(hotKey)); } else { // Dispatch unhandled keypress event for unmapped keys Log.Debug("Unhandled key {key} pressed", key); UnhandledKeyPressed?.Invoke(sender, e); } }
private void ProcessHotKeyEvent(Message m) { var key = (Keys)((ConvertLParam(m.LParam) >> 16) & 0xFFFF); var modifier = (HotKeys.ModifierKeys)(ConvertLParam(m.LParam) & 0xFFFF); HotKeyPressed?.Invoke(this, new KeyPressedEventArgs(new HotKeys(key, modifier))); }
private void OnHotKeyPressed() { _currentDispatcher.Invoke( delegate { HotKeyPressed?.Invoke(this); }); }
public void ProcessHotKey(int id) { var hotKey = HotKeys.SingleOrDefault(key => key.Id == id); if (hotKey != null) { HotKeyPressed?.Invoke(hotKey.Service.ServiceName); } }
protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY) { HotKeyPressed?.Invoke(new HotKey(m.LParam)); } base.WndProc(ref m); }
private void ProcessHotKeyEvent(Message m) { var key = (Keys)((ConvertLParam(m.LParam) >> 16) & 0xFFFF); var modifier = (HotKey.ModifierKeys)(ConvertLParam(m.LParam) & 0xFFFF); Task.Factory.StartNew(() => { HotKeyPressed?.Invoke(this, new KeyPressedEventArgs(new HotKey(key, modifier))); }); }
protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY) { int hotkeyID = m.WParam.ToInt32(); HotKeyPressed?.Invoke(this, new HotKeyPressedEventArgs(hotkeyID)); } base.WndProc(ref m); }
protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY) { HotKeyEventArgs e = new HotKeyEventArgs(m.LParam); HotKeyPressed?.Invoke(null, e); } base.WndProc(ref m); }
private IntPtr HwndHook(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { const int wmHotkey = 0x0312; if (msg == wmHotkey && wParam.ToInt32() == HotKeyId) { HotKeyPressed?.Invoke(); handled = true; } return(IntPtr.Zero); }
/// <summary> /// 热键被按下时第一个触发的方法 /// </summary> /// <param name="msg"></param> /// <param name="handled"></param> private void ThreadPreprocessMessageMethod(ref MSG msg, ref bool handled) { if (!handled) { if (msg.message == NativeMethods.WmHotKey && (int)(msg.wParam) == _id) { HotKeyPressed?.Invoke(this); handled = true; } } }
static HotKeyManager() { Task.Factory.StartNew(() => { Window = new HotKeyMessageWindow(); WindowPtr = Window.Handle; Window.HotKeyPressed += (hotKey) => HotKeyPressed?.Invoke(hotKey); WindowReadyEvent.Set(); Application.Run(Window); }, TaskCreationOptions.LongRunning); }
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) //A Key was pressed down { int vkCode = Marshal.ReadInt32(lParam); //Get the keycode //string theKey = ((Keys)vkCode).ToString(); //Name of the key HotKeyPressed?.Invoke(typeof(Program), vkCode); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); //Call the next hook }
public void RemoveAllHotkeyPressedHandle() { if (HotKeyPressed == null) { return; } foreach (var dlg in HotKeyPressed.GetInvocationList()) { HotKeyPressed -= (EventHandler <HotKeyEventArgs>)dlg; } }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == WmHotKey) { if (_hotKeys.ContainsKey((int)wParam)) { HotKey h = _hotKeys[(int)wParam]; h.RaiseOnHotKeyPressed(); HotKeyPressed?.Invoke(this, new HotKeyEventArgs(h)); } } return(new IntPtr(0)); }
private void hotKeyPressed(object sender, HotKeyEventArgs e) { var hotKey = new HotKey(e.Modifiers, e.Key); bool timedOut = DateTime.Now - _lastKeyPressed > TimeSpan.FromSeconds(10); if (timedOut) { _status = null; _socket = null; } if (_settings.PowerOn.Equals(hotKey)) { _status = PowerStatus.On; Logger.Debug(string.Format("PowerOn HotKey {0} + {1} pressed.", hotKey.Modifier, hotKey.Key)); } else if (_settings.PowerOff.Equals(hotKey)) { _status = PowerStatus.Off; Logger.Debug(string.Format("PowerOff HotKey {0} + {1} pressed.", hotKey.Modifier, hotKey.Key)); } else if (_settings.Undefined.Equals(hotKey)) { _status = PowerStatus.Undefined; Logger.Debug(string.Format("Undefined HotKey {0} + {1} pressed.", hotKey.Modifier, hotKey.Key)); } if (_settings.Sockets.ContainsValue(hotKey)) { _socket = _settings.Sockets.FirstOrDefault(x => x.Value.Equals(hotKey)).Key; Logger.Debug(string.Format("Socket HotKey {0} + {1} ({2}) pressed.", hotKey.Modifier, hotKey.Key, _socket)); } bool statusAndSocketDefined = _status != null && _socket != null; if (statusAndSocketDefined) { HotKeyPressed?.Invoke(this, new HotKeyPressedEventArgs(_socket, (PowerStatus)_status)); _lastKeyPressed = DateTime.MinValue; } _lastKeyPressed = DateTime.Now; }
internal void RegisterHotKey() { if (!string.IsNullOrEmpty(Properties.Settings.Default.HotKey)) { try { hook.RegisterHotKey(); hook.KeyPressed += Hook_KeyPressed; void Hook_KeyPressed(object sender, KeyPressedEventArgs e) { HotKeyPressed?.Invoke(); } } catch (InvalidOperationException ex) { Log.Warn($"key:'{Properties.Settings.Default.HotKey}'", ex); Properties.Settings.Default.HotKey = string.Empty; Properties.Settings.Default.Save(); } } }
// Invoked from MessageWindow to propagate event to consumer's handler private static void OnHotKeyPressed(HotkeyEventArgs e) { //Logger.Current.WriteLine($"keypress key:{e.Key} mods:{e.Modifiers}"); var key = registeredKeys .FirstOrDefault(k => k.Key == (uint)e.Key && k.Modifiers == (uint)(e.Modifiers | Hotmods.NoRepeat)); if (key != null) { if (key.Action != null) { key.Action(); } else { HotKeyPressed?.Invoke(null, e); } } }
/// <summary> /// Raises the <see cref="HotKeyPressed"/> event with the Hotkey Id. /// </summary> public static void RaiseHotKeyPressed(int Id) { HotKeyPressed?.Invoke(Id); }
public void FakeHotKey(ServiceName service) { HotKeyPressed?.Invoke(service); }
public void ThrowHotKeyEvent() { HotKeyPressed?.Invoke(this, null); }
private static void OnHotKeyPressed(HotKeyEventArgs e) { HotKeyPressed?.Invoke(null, e); }
private void OnHotKeyPressed(KeyEventArgs e) { HotKeyPressed?.Invoke(this, e); }
protected static void OnHotKeyPressed(HotKeyEventArgs e) { HotKeyPressed?.Invoke(null, e); }
protected virtual void OnHotKeyPress() { HotKeyPressed?.Invoke(this, new HotKeyEventArgs(this)); }
protected virtual void OnHotKeyPressed() { HotKeyPressed?.Invoke(this, EventArgs.Empty); }
private void ThrowHotKeyEvent() { HotKeyPressed?.Invoke(this, null); }
private void RaiseHotKeyPressed() => HotKeyPressed?.Invoke(this, EventArgs.Empty);
private void OnHotKeyPressed() { HotKeyPressed?.Invoke(this); }
private void OnHotKeyPressed() { HotKeyPressed?.Invoke(this, EventArgs.Empty); }