全局钩子定义
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace WindowsFormsApp1
{
public static class GlobalMousePosition
{
#region 获取鼠标当前位置
public const int WH_MOUSE_LL = 14;
public enum MouseMessages
{
WM_MOUSEMOVE = 0x0200
}
public delegate int LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool

该代码示例展示了如何在C#中使用全局低级鼠标钩子(WH_MOUSE_LL)来捕获鼠标移动事件,并模拟鼠标点击。通过SetWindowsHookEx函数注册钩子,HookCallback方法处理鼠标事件,更新鼠标位置信息。此外,还提供了SimulateMouseClick函数来模拟鼠标点击。
最低0.47元/天 解锁文章
3841

被折叠的 条评论
为什么被折叠?



