zoukankan      html  css  js  c++  java
  • 注册系统热键

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;

    namespace DataSource
    {
        public partial class HotKey : Form
        {
            [DllImport("user32")]
            public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);
            //注册热键的api
            [DllImport("user32")]
            public static extern bool UnregisterHotKey(IntPtr hWnd, int id);


            public HotKey()
            {
                InitializeComponent();
            }

            private void HotKey_Load(object sender, EventArgs e)
            {
                //注册热键(窗体句柄,热键ID,辅助键,实键)
                RegisterHotKey(this.Handle, 888, 3, Keys.B);

            }

            private void HotKey_FormClosing(object sender, FormClosingEventArgs e)
            {
                //注消热键(句柄,热键ID)
                UnregisterHotKey(this.Handle, 888);

            }

            protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                    case 0x0312: //这个是window消息定义的 注册的热键消息
                        if (m.WParam.ToString().Equals("888")) //如果是我们注册的那个热键
                            if (this.Visible == false)
                            {
                                this.Visible = true;
                            }
                            else
                            {
                                this.Visible = false;
                            }
                        break;
                }
                base.WndProc(ref m);
            }

            //辅助键说明:
            //None = 0,
            //Alt = 1,
            //crtl= 2,
            //Shift = 4,
            //Windows = 8

        }
    }

  • 相关阅读:
    python之地基(一)
    pickle库的使用详解
    Python骚操作:动态定义函数
    10个高效的pandas技巧
    Python趣味应用 | AI告诉你张无忌最爱的竟是
    兵贵神速!掌握这10个python技巧,让你代码工作如鱼得水!
    python选方向?大数据的职位你了解多少
    python入门学习--小白篇(用python绘制五角星)
    如何让 python 处理速度翻倍?内含代码
    核心Python知识(一)
  • 原文地址:https://www.cnblogs.com/tianguook/p/1713794.html
Copyright © 2011-2022 走看看