我正在使用以下库:http://www.codeproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library?fid=1518257&df=90&mpp=25&noise=3&prof=False&sort=Position&view=Quick&fr=51#xx0xx,它与低级 Windows 7 鼠标钩子一起使用。我创建了一个计时器来检查最后一次鼠标移动事件发生的时间,如果超过给定时间,我就会使用 SetCursorPos(0,0) 将鼠标移到屏幕左上角。
在移动鼠标之前,我获取了它的旧坐标并保存了起来。因此,当我接收到下一个MouseMove事件时,我可以将鼠标放回原来的位置。但是,在调用SetCursorPos(oldPos.x, oldPos.y)之后,鼠标没有移动。
我确信oldPos的值是正确的,但是光标拒绝移动。这可能是由于我使用的库引起的吗?请帮忙看看。
在移动鼠标之前,我获取了它的旧坐标并保存了起来。因此,当我接收到下一个MouseMove事件时,我可以将鼠标放回原来的位置。但是,在调用SetCursorPos(oldPos.x, oldPos.y)之后,鼠标没有移动。
我确信oldPos的值是正确的,但是光标拒绝移动。这可能是由于我使用的库引起的吗?请帮忙看看。
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
void mouseHook_MouseMove(object sender, MouseEventArgs e)
{
//If the mouse was not visible, move it back to it's original position
if (!mouseVisible)
{
mouseVisible = true;
SetCursorPos(cursorPosition.x, cursorPosition.y);
}
//Update the last moved time.
lastMoved = DateTime.Now;
}
private void hideMouse(object sender, EventArgs e)
{
if (mouseVisible && (DateTime.Now - lastMoved) > new TimeSpan(0, 0, 0, mouseControl.timeTrackBar.Value))
{
log.Debug("Hiding mouse.");
//Store the current mouse position.
GetCursorPos(out cursorPosition);
//Hide the mouse.
SetCursorPos(0, 0);
log.Debug("Moving cursor to 0,0");
mouseVisible = false;
}