国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

C#鉤子類 幾乎捕獲鍵盤鼠標(biāo)所有事件

2019-11-17 02:49:25
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
C#鉤子類 幾乎捕獲鍵盤鼠標(biāo)所有事件
  1. usingSystem;
  2. usingSystem.Text;
  3. usingSystem.Runtime.InteropServices;
  4. usingSystem.Reflection;
  5. usingSystem.Windows.Forms;
  6. namespaceMouseKeyboardLibrary
  7. {
  8. ///<summary>
  9. ///AbstractbaseclassforMouseandKeyboardhooks
  10. ///</summary>
  11. publicabstractclassGlobalHook
  12. {
  13. #regionWindowsAPICode
  14. [StructLayout(LayoutKind.Sequential)]
  15. PRotectedclassPOINT
  16. {
  17. publicintx;
  18. publicinty;
  19. }
  20. [StructLayout(LayoutKind.Sequential)]
  21. protectedclassMouseHookStruct
  22. {
  23. publicPOINTpt;
  24. publicinthwnd;
  25. publicintwHitTestCode;
  26. publicintdwExtraInfo;
  27. }
  28. [StructLayout(LayoutKind.Sequential)]
  29. protectedclassMouseLLHookStruct
  30. {
  31. publicPOINTpt;
  32. publicintmouseData;
  33. publicintflags;
  34. publicinttime;
  35. publicintdwExtraInfo;
  36. }
  37. [StructLayout(LayoutKind.Sequential)]
  38. protectedclassKeyboardHookStruct
  39. {
  40. publicintvkCode;
  41. publicintscanCode;
  42. publicintflags;
  43. publicinttime;
  44. publicintdwExtraInfo;
  45. }
  46. [DllImport("user32.dll",CharSet=CharSet.Auto,
  47. CallingConvention=CallingConvention.StdCall,SetLastError=true)]
  48. protectedstaticexternintSetWindowsHookEx(
  49. intidHook,
  50. HookProclpfn,
  51. IntPtrhMod,
  52. intdwThreadId);
  53. [DllImport("user32.dll",CharSet=CharSet.Auto,
  54. CallingConvention=CallingConvention.StdCall,SetLastError=true)]
  55. protectedstaticexternintUnhookWindowsHookEx(intidHook);
  56. [DllImport("user32.dll",CharSet=CharSet.Auto,
  57. CallingConvention=CallingConvention.StdCall)]
  58. protectedstaticexternintCallNextHookEx(
  59. intidHook,
  60. intnCode,
  61. intwParam,
  62. IntPtrlParam);
  63. [DllImport("user32")]
  64. protectedstaticexternintToAscii(
  65. intuVirtKey,
  66. intuScanCode,
  67. byte[]lpbKeyState,
  68. byte[]lpwTransKey,
  69. intfuState);
  70. [DllImport("user32")]
  71. protectedstaticexternintGetKeyboardState(byte[]pbKeyState);
  72. [DllImport("user32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
  73. protectedstaticexternshortGetKeyState(intvKey);
  74. protecteddelegateintHookProc(intnCode,intwParam,IntPtrlParam);
  75. protectedconstintWH_MOUSE_LL=14;
  76. protectedconstintWH_KEYBOARD_LL=13;
  77. protectedconstintWH_MOUSE=7;
  78. protectedconstintWH_KEYBOARD=2;
  79. protectedconstintWM_MOUSEMOVE=0x200;
  80. protectedconstintWM_LBUTTONDOWN=0x201;
  81. protectedconstintWM_RBUTTONDOWN=0x204;
  82. protectedconstintWM_MBUTTONDOWN=0x207;
  83. protectedconstintWM_LBUTTONUP=0x202;
  84. protectedconstintWM_RBUTTONUP=0x205;
  85. protectedconstintWM_MBUTTONUP=0x208;
  86. protectedconstintWM_LBUTTONDBLCLK=0x203;
  87. protectedconstintWM_RBUTTONDBLCLK=0x206;
  88. protectedconstintWM_MBUTTONDBLCLK=0x209;
  89. protectedconstintWM_MOUSEWHEEL=0x020A;
  90. protectedconstintWM_KEYDOWN=0x100;
  91. protectedconstintWM_KEYUP=0x101;
  92. protectedconstintWM_SYSKEYDOWN=0x104;
  93. protectedconstintWM_SYSKEYUP=0x105;
  94. protectedconstbyteVK_SHIFT=0x10;
  95. protectedconstbyteVK_CAPITAL=0x14;
  96. protectedconstbyteVK_NUMLOCK=0x90;
  97. protectedconstbyteVK_LSHIFT=0xA0;
  98. protectedconstbyteVK_RSHIFT=0xA1;
  99. protectedconstbyteVK_LCONTROL=0xA2;
  100. protectedconstbyteVK_RCONTROL=0x3;
  101. protectedconstbyteVK_LALT=0xA4;
  102. protectedconstbyteVK_RALT=0xA5;
  103. protectedconstbyteLLKHF_ALTDOWN=0x20;
  104. #endregion
  105. #regionPrivateVariables
  106. protectedint_hookType;
  107. protectedint_handleToHook;
  108. protectedbool_isStarted;
  109. protectedHookProc_hookCallback;
  110. #endregion
  111. #regionProperties
  112. publicboolIsStarted
  113. {
  114. get
  115. {
  116. return_isStarted;
  117. }
  118. }
  119. #endregion
  120. #regionConstructor
  121. publicGlobalHook()
  122. {
  123. application.ApplicationExit+=newEventHandler(Application_ApplicationExit);
  124. }
  125. #endregion
  126. #regionMethods
  127. publicvoidStart()
  128. {
  129. if(!_isStarted&&
  130. _hookType!=0)
  131. {
  132. //Makesurewekeepareferencetothisdelegate!
  133. //Ifnot,GCrandomlycollectsit,andaNullReferenceexceptionisthrown
  134. _hookCallback=newHookProc(HookCallbackProcedure);
  135. _handleToHook=SetWindowsHookEx(
  136. _hookType,
  137. _hookCallback,
  138. Marshal.GetHINSTANCE(Assembly.GetExecutingA
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平和县| 双江| 漳州市| 古交市| 安多县| 丹寨县| 临汾市| 白水县| 广平县| 普兰店市| 分宜县| 孝昌县| 方正县| 朔州市| 成武县| 界首市| 阿尔山市| 双峰县| 连平县| 肥西县| 黎川县| 苍南县| 乌苏市| 河曲县| 崇州市| 凯里市| 松溪县| 玛沁县| 修武县| 安塞县| 乾安县| 翁牛特旗| 根河市| 盘锦市| 邻水| 大方县| 喀喇| 临邑县| 德保县| 温泉县| 五峰|