//定义键盘消息结构体
public struct KeyMSG
{
public int vkCode; //键盘虚拟码(1-254)
public int scanCode; //硬件扫描码
public int flags; //键盘按下时等于128;键盘抬起时等于0
public int time; //windows运行时间
public int dwExtranInfo;
}
//定义变量
public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);
static int hKeyboardHook = 0;
HookProc KeyboardHookProcedure;
//安装钩子(需要命名空间:System.Runtime.InteropServices)
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook,HookProc lpfn,IntPtr hInstance,int threadId);
//卸载钩子
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
pub
C# 键盘钩子入门
最新推荐文章于 2024-05-28 13:19:24 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)