コード例 #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);
            }
        }
コード例 #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)));
        }
コード例 #3
0
ファイル: HotKey.cs プロジェクト: uzbekdev1/ImgurSniper
 private void OnHotKeyPressed()
 {
     _currentDispatcher.Invoke(
         delegate {
         HotKeyPressed?.Invoke(this);
     });
 }
コード例 #4
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_HOTKEY)
            {
                HotKeyPressed?.Invoke(new HotKey(m.LParam));
            }

            base.WndProc(ref m);
        }
コード例 #5
0
        public void ProcessHotKey(int id)
        {
            var hotKey = HotKeys.SingleOrDefault(key => key.Id == id);

            if (hotKey != null)
            {
                HotKeyPressed?.Invoke(hotKey.Service.ServiceName);
            }
        }
コード例 #6
0
ファイル: HotKeyHandler.cs プロジェクト: yorkrj/FluxPrompt
        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);
        }
コード例 #7
0
            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);
            }
コード例 #8
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)));
            });
        }
コード例 #9
0
ファイル: GlobelHotKey.cs プロジェクト: fujieda/BurageSnap
        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);
        }
コード例 #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;
         }
     }
 }
コード例 #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);
 }
コード例 #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
        }
コード例 #13
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));
        }
コード例 #14
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;
        }
コード例 #15
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();
         }
     }
 }
コード例 #16
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);
                }
            }
        }
コード例 #17
0
 private void OnHotKeyPressed()
 {
     HotKeyPressed?.Invoke(this);
 }
コード例 #18
0
 private void RaiseHotKeyPressed() => HotKeyPressed?.Invoke(this, EventArgs.Empty);
コード例 #19
0
ファイル: ServiceProvider.cs プロジェクト: zeud/Captura
 /// <summary>
 /// Raises the <see cref="HotKeyPressed"/> event with the Hotkey Id.
 /// </summary>
 public static void RaiseHotKeyPressed(int Id)
 {
     HotKeyPressed?.Invoke(Id);
 }
コード例 #20
0
 public void FakeHotKey(ServiceName service)
 {
     HotKeyPressed?.Invoke(service);
 }
コード例 #21
0
 public void ThrowHotKeyEvent()
 {
     HotKeyPressed?.Invoke(this, null);
 }
コード例 #22
0
 private static void OnHotKeyPressed(HotKeyEventArgs e)
 {
     HotKeyPressed?.Invoke(null, e);
 }
コード例 #23
0
 private void OnHotKeyPressed()
 {
     HotKeyPressed?.Invoke(this, EventArgs.Empty);
 }
コード例 #24
0
 private void OnHotKeyPressed(KeyEventArgs e)
 {
     HotKeyPressed?.Invoke(this, e);
 }
コード例 #25
0
ファイル: HotKeyManager.cs プロジェクト: BesuglovS/nudata
 protected static void OnHotKeyPressed(HotKeyEventArgs e)
 {
     HotKeyPressed?.Invoke(null, e);
 }
コード例 #26
0
 protected virtual void OnHotKeyPress()
 {
     HotKeyPressed?.Invoke(this, new HotKeyEventArgs(this));
 }
コード例 #27
0
 protected virtual void OnHotKeyPressed()
 {
     HotKeyPressed?.Invoke(this, EventArgs.Empty);
 }
コード例 #28
0
 private void ThrowHotKeyEvent()
 {
     HotKeyPressed?.Invoke(this, null);
 }