Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
        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)));
        }
Esempio n. 3
0
 private void OnHotKeyPressed()
 {
     _currentDispatcher.Invoke(
         delegate {
         HotKeyPressed?.Invoke(this);
     });
 }
Esempio n. 4
0
        public void ProcessHotKey(int id)
        {
            var hotKey = HotKeys.SingleOrDefault(key => key.Id == id);

            if (hotKey != null)
            {
                HotKeyPressed?.Invoke(hotKey.Service.ServiceName);
            }
        }
Esempio n. 5
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_HOTKEY)
            {
                HotKeyPressed?.Invoke(new HotKey(m.LParam));
            }

            base.WndProc(ref m);
        }
Esempio n. 6
0
        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)));
            });
        }
Esempio n. 7
0
        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);
            }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 /// <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;
         }
     }
 }
Esempio n. 11
0
 static HotKeyManager()
 {
     Task.Factory.StartNew(() =>
     {
         Window                = new HotKeyMessageWindow();
         WindowPtr             = Window.Handle;
         Window.HotKeyPressed += (hotKey) => HotKeyPressed?.Invoke(hotKey);
         WindowReadyEvent.Set();
         Application.Run(Window);
     }, TaskCreationOptions.LongRunning);
 }
Esempio n. 12
0
        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
        }
Esempio n. 13
0
 public void RemoveAllHotkeyPressedHandle()
 {
     if (HotKeyPressed == null)
     {
         return;
     }
     foreach (var dlg in HotKeyPressed.GetInvocationList())
     {
         HotKeyPressed -= (EventHandler <HotKeyEventArgs>)dlg;
     }
 }
Esempio n. 14
0
        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));
        }
Esempio n. 15
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;
        }
Esempio n. 16
0
 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();
         }
     }
 }
Esempio n. 17
0
        // 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);
                }
            }
        }
Esempio n. 18
0
 /// <summary>
 /// Raises the <see cref="HotKeyPressed"/> event with the Hotkey Id.
 /// </summary>
 public static void RaiseHotKeyPressed(int Id)
 {
     HotKeyPressed?.Invoke(Id);
 }
Esempio n. 19
0
 public void FakeHotKey(ServiceName service)
 {
     HotKeyPressed?.Invoke(service);
 }
Esempio n. 20
0
 public void ThrowHotKeyEvent()
 {
     HotKeyPressed?.Invoke(this, null);
 }
Esempio n. 21
0
 private static void OnHotKeyPressed(HotKeyEventArgs e)
 {
     HotKeyPressed?.Invoke(null, e);
 }
Esempio n. 22
0
 private void OnHotKeyPressed(KeyEventArgs e)
 {
     HotKeyPressed?.Invoke(this, e);
 }
Esempio n. 23
0
 protected static void OnHotKeyPressed(HotKeyEventArgs e)
 {
     HotKeyPressed?.Invoke(null, e);
 }
Esempio n. 24
0
 protected virtual void OnHotKeyPress()
 {
     HotKeyPressed?.Invoke(this, new HotKeyEventArgs(this));
 }
Esempio n. 25
0
 protected virtual void OnHotKeyPressed()
 {
     HotKeyPressed?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 26
0
 private void ThrowHotKeyEvent()
 {
     HotKeyPressed?.Invoke(this, null);
 }
Esempio n. 27
0
 private void RaiseHotKeyPressed() => HotKeyPressed?.Invoke(this, EventArgs.Empty);
Esempio n. 28
0
 private void OnHotKeyPressed()
 {
     HotKeyPressed?.Invoke(this);
 }
Esempio n. 29
0
 private void OnHotKeyPressed()
 {
     HotKeyPressed?.Invoke(this, EventArgs.Empty);
 }