I use the following library: 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
To help me work with low-mouse hooks in Windows 7. I create a timer to check the last time the mouse move event was fired, and if it is longer than a certain time, I move the mouse to the upper left corner of the screen using SetCursorPos (0,0)
Before moving the mouse, I took the old coordinates and saved them. So when I get the following MouseMove event, I can replace the mouse at its original location. However, after calling SetCursorPos (oldPos.x, oldPos.y), the mouse does not move.
I am sure that the oldPos values โโare correct, however the cursor refuses to move. Could this be due to the library I'm using? Please help.
[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 (!mouseVisible)
{
mouseVisible = true;
SetCursorPos(cursorPosition.x, cursorPosition.y);
}
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.");
GetCursorPos(out cursorPosition);
SetCursorPos(0, 0);
log.Debug("Moving cursor to 0,0");
mouseVisible = false;
}
source
share