跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

提交记录
修改Core/Librarys/Win32API.cs+41 −0看文件
@@ -1,5 +1,6 @@
11using System;
22using System.Collections.Generic;
3新增:using System.Diagnostics;
34using System.Linq;
45using System.Runtime.InteropServices;
56using System.Text;
@@ -197,5 +198,45 @@ namespace Core.Librarys
197198 // the rest is not defined/needed
198199 }
199200 #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
200241 }
201242}