Esempio n. 1
0
 public void StarHotKey()
 {
     if (m_WindowHandle != IntPtr.Zero)
     {
         if (!RegisterHotKey(m_WindowHandle, m_WParam, m_ModKey, m_Keys))
         {
             throw new Exception("Failed to register hotkey");
         }
         try
         {
             m_HotKeyWnd.m_HotKeyPass = new HotKeyPass(KeyPass);
             m_HotKeyWnd.m_WParam     = m_WParam;
             m_HotKeyWnd.AssignHandle(m_WindowHandle);
             Star = true;
         }
         catch
         {
             StopHotKey();
         }
     }
 }
Esempio n. 2
0
 public void Bind()
 {
     if (_windowHandle != IntPtr.Zero)
     {
         if (!RegisterHotKey(_windowHandle, _WParam, _modKey, _keys))
         {
             MessageBox.Show("Failed to bind hotkey!");
         }
         try
         {
             _hotKeyWnd.m_HotKeyPass = new HotKeyPass(KeyPass);
             _hotKeyWnd.m_WParam     = _WParam;
             _hotKeyWnd.AssignHandle(_windowHandle);
             _bind = true;
         }
         catch
         {
             Unbind();
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 开始注册系统全局热键
 /// </summary>
 public void StarHotKey()
 {
     if (m_WindowHandle != IntPtr.Zero)
     {
         if (!RegisterHotKey(m_WindowHandle, m_WParam, m_ModKey, m_Keys))
         {
             throw new Exception("注册热键失败");
         }
         try
         {
             m_HotKeyWnd.m_HotKeyPass = new HotKeyPass(KeyPass);
             m_HotKeyWnd.m_WParam     = m_WParam;
             m_HotKeyWnd.AssignHandle(m_WindowHandle);
             Star = true;
         }
         catch (Exception ex)
         {
             LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(RegisterHotKeyHelper));
             StopHotKey();
         }
     }
 }
Esempio n. 4
0
File: Misc.cs Progetto: LouisMT/NFU
        /// <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);
            }
        }