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

        }
    }

  • 相关阅读:
    手持设备开发项目实例二(盘点扫描系统)
    通过Netty通信,采集设备现场GPS数据,并存放在redis服务器。
    自动立体车库控制应用系统
    Miscorsoft AnalysisServices 开发
    日志分析常用命令
    MVC中 @ResponseBody、@RequestMapping
    spring与redis集成之aop整合方案
    工业控制系统之葡萄酒保温发酵控制系统
    JS闭包分享
    架构之美—数据库架构
  • 原文地址:https://www.cnblogs.com/tianguook/p/1713794.html
Copyright © 2011-2022 走看看