我使用user32.dll来获取光标位置和模拟鼠标点击等。我正在使用WPF app.But中的MouseLeave事件,我想从所有窗口(不仅仅是我的WPF应用程序)捕获鼠标离开(或鼠标悬停)事件。是否有可能使用user32.dll或其他方法来捕获此事件?
发布于 2019-04-12 11:49:06
我是这样做的
[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);
}
}));
}
发布于 2019-04-11 05:35:37
有一个Windows API调用,它允许获取鼠标事件,即使它们不在窗口中:
SetCapture(hWnd)
您可以将其与以下调用结合使用:
WindowFromPoint()
获取鼠标停留在哪个窗口上
https://stackoverflow.com/questions/55621288
复制相似问题