Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Hotkey"/> class.
        /// </summary>
        /// <param name="hotkey">The hotkey in string format.</param>
        public Hotkey(string hotkey)
        {
            var hotkeyObj = HotkeyRepresentation.AsHotkey(hotkey);

            KeyCode   = hotkeyObj.KeyCode;
            Modifiers = hotkeyObj.Modifiers;
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a hotkey to the global Key watcher.
        /// </summary>
        /// <param name="hotkey">The hotkey to add.</param>
        /// <returns>
        /// True if successful or false if not. Ensure you inform the user if the hotkey fails to be
        /// registered. This is mostly due to a hotkey being already in use by another application.
        /// </returns>
        public bool Add(Hotkey hotkey)
        {
            if (hotkey.Modifiers == Keys.LWin || hotkey.Modifiers == Keys.RWin)
            {
                return(false);
            }

            return(Add(HotkeyRepresentation.AsString(hotkey)));
        }
Esempio n. 3
0
 /// <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);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Removes any specific hotkey from the global Key watcher.
 /// </summary>
 /// <param name="hotkey">The hotkey to remove.</param>
 public void Remove(Hotkey hotkey)
 {
     _handle.RemoveKey(HotkeyRepresentation.AsString(hotkey));
 }