C# SetWindowsHookEx

  [DllImport("user32.dll")]
        static extern IntPtr SetWindowsHookEx(int idHook, keyboardHookProc callback, IntPtr hInstance, uint threadId);

        /// <summary>
        /// 安装钩子
        /// </summary>
        /// <param name="idHook">钩子类型 13键盘和14鼠标,用来对底层输入事件监视</param>
        /// <param name="callback">函数指针</param>
        /// <param name="hInstance">包含SetWindowsHookEx函数的模块地址,user32.dll入口</param>
        /// <param name="threadId">0表示系统钩子,</param>
        /// <param name="str"></param>
        /// <returns></returns>
        public IntPtr SetWindowsHookEx(int idHook, keyboardHookProc callback, IntPtr hInstance, uint threadId, string str = "占位符")
        {
            return SetWindowsHookEx(idHook, callback, hInstance, threadId);
        }

 

     public event KeyEventHandler KeyDown;
        private void button7_Click(object sender, EventArgs e)
        {
            this.KeyDown += new KeyEventHandler(gkh_KeyDown); //绑定事件
            Keys key = (Keys)1;
            KeyEventArgs kea = new KeyEventArgs(key);
            KeyDown(this, kea);
        }
        private void gkh_KeyDown(object sender, KeyEventArgs e)
        {
            MessageBox.Show("000111");
        }

 

转载于:https://www.cnblogs.com/enych/p/10334869.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值