Exemplo n.º 1
0
        public void Register(int id, Hotkey hotkey)
        {
            Keys key = (Keys)hotkey.Key;
            HotkeyModifierKeys modifiers = HotkeyModifierKeys.None;

            if ((hotkey.Modifiers & VirtualKeyModifiers.Control) == VirtualKeyModifiers.Control)
            {
                modifiers |= HotkeyModifierKeys.Control;
            }

            if ((hotkey.Modifiers & VirtualKeyModifiers.Menu) == VirtualKeyModifiers.Menu)
            {
                modifiers |= HotkeyModifierKeys.Alt;
            }

            if ((hotkey.Modifiers & VirtualKeyModifiers.Shift) == VirtualKeyModifiers.Shift)
            {
                modifiers |= HotkeyModifierKeys.Shift;
            }

            if ((hotkey.Modifiers & VirtualKeyModifiers.Windows) == VirtualKeyModifiers.Windows)
            {
                modifiers |= HotkeyModifierKeys.Win;
            }

            var nativeId = _hotkeyHook.RegisterHotKey(modifiers, key);

            _hotkeys.Add(new HotkeyEntry(id, nativeId, key, modifiers));
        }
Exemplo n.º 2
0
 public HotkeyEntry(int id, int nativeId, Keys key, HotkeyModifierKeys modifiers)
 {
     Id        = id;
     NativeId  = nativeId;
     Key       = key;
     Modifiers = modifiers;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Registers a hot key in the system.
        /// </summary>
        /// <param name="modifier">The modifiers that are associated with the hot key.</param>
        /// <param name="key">The key itself that is associated with the hot key.</param>
        public int RegisterHotKey(HotkeyModifierKeys modifier, Keys key)
        {
            // increment the counter.
            _currentId = _currentId + 1;

            // register the hot key.
            if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
            {
                throw new InvalidOperationException("Couldn’t register the hot key.");
            }

            return(_currentId);
        }
Exemplo n.º 4
0
            /// <summary>
            /// Overridden to get the notifications.
            /// </summary>
            /// <param name="m"></param>
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);

                // check if we got a hot key pressed.
                if (m.Msg == WM_HOTKEY)
                {
                    // get the keys.
                    Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
                    HotkeyModifierKeys modifier = (HotkeyModifierKeys)((int)m.LParam & 0xFFFF);

                    // invoke the event to notify the parent.
                    KeyPressed?.Invoke(this, new HotkeyPressedEventArgs(modifier, key));
                }
            }
 internal HotkeyPressedEventArgs(HotkeyModifierKeys modifier, Keys key)
 {
     _modifier = modifier;
     _key      = key;
 }