Exemple #1
0
 public void Unbind()
 {
     if (_bind)
     {
         if (!UnregisterHotKey(_windowHandle, _WParam))
         {
             throw new Exception("");
         }
         _bind = false;
         _hotKeyWnd.ReleaseHandle();
     }
 }
Exemple #2
0
 public void StopHotKey()
 {
     if (Star)
     {
         if (!UnregisterHotKey(m_WindowHandle, m_WParam))
         {
             throw new Exception("");
         }
         Star = false;
         m_HotKeyWnd.ReleaseHandle();
     }
 }
Exemple #3
0
        /// <summary>
        /// Bind a hotkey to a method.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="method">The method.</param>
        /// <param name="id">The bind ID.</param>
        /// <param name="handle">The handle.</param>
        public static bool RegisterHotKey(Keys key, Action method, int id, IntPtr handle)
        {
            var hotKeyWnd = new HotKeyWndProc();

            if (!RegisterHotKey(handle, id, 0, key))
            {
                HandleError(new Win32Exception(string.Format(Resources.RegisterHotKeyFailed, key)), Resources.RegisterHotKey);
                return(false);
            }

            try
            {
                hotKeyWnd.HotKeyPass = new HotKeyPass(method);
                hotKeyWnd.WParam     = id;
                hotKeyWnd.AssignHandle(handle);
                return(true);
            }
            catch
            {
                hotKeyWnd.ReleaseHandle();
                return(false);
            }
        }