提交记录修改Core/Librarys/Win32API.cs+41 −0看文件
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | using System; |
| 2 | 2 | using System.Collections.Generic; |
| 3 | 新增:using System.Diagnostics; | |
| 3 | 4 | using System.Linq; |
| 4 | 5 | using System.Runtime.InteropServices; |
| 5 | 6 | using System.Text; |
| @@ -197,5 +198,45 @@ namespace Core.Librarys | ||
| 197 | 198 | // the rest is not defined/needed |
| 198 | 199 | } |
| 199 | 200 | #endregion |
| 201 | 新增: | |
| 202 | 新增: #region 键盘钩子 | |
| 203 | 新增: private const int WH_KEYBOARD_LL = 13; | |
| 204 | 新增: public const int WM_KEYDOWN = 0x0100; | |
| 205 | 新增: | |
| 206 | 新增: /// <summary> | |
| 207 | 新增: /// 设置键盘钩子 | |
| 208 | 新增: /// </summary> | |
| 209 | 新增: /// <param name="proc"></param> | |
| 210 | 新增: /// <returns></returns> | |
| 211 | 新增: public static IntPtr SetKeyboardHook(LowLevelKeyboardProc proc) | |
| 212 | 新增: { | |
| 213 | 新增: using (Process curProcess = Process.GetCurrentProcess()) | |
| 214 | 新增: using (ProcessModule curModule = curProcess.MainModule) | |
| 215 | 新增: { | |
| 216 | 新增: return SetWindowsHookEx(WH_KEYBOARD_LL, proc, | |
| 217 | 新增: GetModuleHandle(curModule.ModuleName), 0); | |
| 218 | 新增: } | |
| 219 | 新增: } | |
| 220 | 新增: | |
| 221 | 新增: public delegate IntPtr LowLevelKeyboardProc( | |
| 222 | 新增: int nCode, IntPtr wParam, IntPtr lParam); | |
| 223 | 新增: | |
| 224 | 新增: | |
| 225 | 新增: | |
| 226 | 新增: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
| 227 | 新增: public static extern IntPtr SetWindowsHookEx(int idHook, | |
| 228 | 新增: LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); | |
| 229 | 新增: | |
| 230 | 新增: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
| 231 | 新增: [return: MarshalAs(UnmanagedType.Bool)] | |
| 232 | 新增: public static extern bool UnhookWindowsHookEx(IntPtr hhk); | |
| 233 | 新增: | |
| 234 | 新增: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
| 235 | 新增: public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, | |
| 236 | 新增: IntPtr wParam, IntPtr lParam); | |
| 237 | 新增: | |
| 238 | 新增: [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
| 239 | 新增: public static extern IntPtr GetModuleHandle(string lpModuleName); | |
| 240 | 新增: #endregion | |
| 200 | 241 | } |
| 201 | 242 | } |

