MicrosoftVisualStudio2010做的C#简单的鼠标钩子应用实例实例,实现实时监控鼠标位置(需要编译后,在Release文件夹那里运行)主要代码:publicdelegateintHookProc(intnCode,IntPtrwParam,IntPtrlParam);//定义钩子句柄publicstaticintm_iHock=0;//定义钩子类型publicconstintWH_MOUSE_LL=14;publicHookProcHookProcVar;//安装钩子[DllImport("user32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]publicstaticexternintSetWindowsHookEx(intidHook,HookProclpfn,IntPtrhInstance,intthreadId);//卸载钩子[DllImport("user32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]publicstaticexternboolUnhookWindowsHookEx(intidHook);//调用下一个钩子[DllImport("user32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]publicstaticexternintCallNextHookEx(intidHook,intnCode,IntPtrwParam,IntPtrlParam);[StructLayout(LayoutKind.Sequential)]
1