我正在使用 user32.dll 获取光标位置和模拟鼠标点击等。我在 WPF 应用程序中使用 MouseLeave 事件。但是我想从所有窗口捕获鼠标离开(或鼠标悬停)事件(不是仅在我的 WPF 应用程序中)。是否可以使用 user32.dll 或其他方式捕获此事件?
最佳答案
我是这样做的
[DllImport("user32.dll")]
static extern bool GetCursorPos(out Point lpPoint);
void StartGettingCursorPos()
{
Task.Run(new Action(() =>
{
while (true)
{
GetCursorPos(out Point point);
Console.WriteLine($"X:{point.X}; Y:{point.Y}");
Thread.Sleep(20);
}
}));
}
关于c# - 如何使用 user32.dll 捕获鼠标离开事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55621288/