c# 全局钩子之键盘 (实例)
新建项目WinAPIMessage
新建一个form1窗体.增加2个button,增加事件。。然后复制如下面代码替换form1的代码(注意不要忘记增加button事件.
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;
using System.Reflection;
using System.Diagnostics;
namespace WinAPIMessage
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//委托
public delegate int HookProc(int nCode, int wParam, IntPtr lParam);
static int hHook = 0;
public const int WH_KEYBOARD_LL = 13;
//LowLevel键盘截获,如果是WH_KEYBOARD=2,并不能对系统键盘截取,Acrobat Reader会在你截取之前获得键盘。
HookProc KeyBoardHookProcedure;
//键盘Hook结构函数
[StructLayout(LayoutKind.Sequential)]
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余4页未读,立即下载