Пример #1
0
        /// <summary>
        /// 全局热键处理
        /// </summary>
        /// <param name="m">消息</param>
        protected override void WndProc(ref Message m)
        {
            const int WM_HOTKEY = 0x0312;

            if (m.Msg == WM_HOTKEY)
            {
                switch (m.WParam.ToInt32())
                {
                case 100:
                    if (runningStatus)
                    {
                        Stop();
                    }
                    else
                    {
                        Start();
                    }

                    break;

                case 101:
                    IntPtr        FGHwnd      = GetForegroundWindow();
                    int           length      = GetWindowTextLength(FGHwnd);
                    StringBuilder windowTitle = new StringBuilder(length + 1);
                    GetWindowText(FGHwnd, windowTitle, windowTitle.Capacity);
                    txtboxWindowTitle.Text = windowTitle.ToString();
                    Hotkey.UnregisterHotKey(Handle, 101);
                    btnCaptureWindowTitle.Text = "捕获窗口标题";
                    break;
                }
            }
            base.WndProc(ref m);
        }
Пример #2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Hotkey.UnregisterHotKey(Handle, 100);
            int key = comboBox1.SelectedIndex + 112;

            Hotkey.RegisterHotKey(Handle, 100, Hotkey.KeyModifiers.None, key);
        }
Пример #3
0
        private void comboboxHotkey_SelectedIndexChanged(object sender, EventArgs e)
        {
            Hotkey.UnregisterHotKey(Handle, 100);
            int key = comboboxHotkey.SelectedIndex + 112;

            if (!Hotkey.RegisterHotKey(Handle, 100, Hotkey.KeyModifiers.None, key))
            {
                MessageBox.Show("热键注册失败,请尝试关闭热键冲突的程序或更改热键", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboboxHotkey.SelectedIndex = -1;
            }
        }
Пример #4
0
 private void btnCaptureWindowTitle_Click(object sender, EventArgs e)
 {
     Hotkey.UnregisterHotKey(Handle, 101);
     if (Hotkey.RegisterHotKey(Handle, 101, Hotkey.KeyModifiers.Shift, 113))
     {
         btnCaptureWindowTitle.Text = "请转到对应的窗口按下Shift+F2...";
     }
     else
     {
         MessageBox.Show("热键注册失败,请尝试关闭热键冲突的程序或手动输入窗口标题", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Пример #5
0
 private void formMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     //退出前卸载热键
     Hotkey.UnregisterHotKey(Handle, 100);
     Hotkey.UnregisterHotKey(Handle, 101);
     //保存设置
     SaveConfig();
     if (currentThreadID != 0)
     {
         Stop();
     }
 }
Пример #6
0
 private void formMain_FormClosing(object sender, FormClosingEventArgs e)//退出前卸载热键
 {
     Hotkey.UnregisterHotKey(Handle, 100);
     Hotkey.UnregisterHotKey(Handle, 101);
 }