Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After i moved the mouse i want to move the mouse pointer to his original position.

How can i move the cursor position to a position that i want
Posted

1 solution

Unfortunately, it may require the use of P/Invoke: http://en.wikipedia.org/wiki/PInvoke[^].

The most comprehensive way is the use of the very low-level Windows API SendInput: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

This is how it looks in .NET via P/Invoke: http://www.pinvoke.net/default.aspx/user32.sendinput[^].

(Very simple. Everything is already done for you. Isn't that nice? :-))

The simpler way is using SetCursorPos:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms648394%28v=vs.85%29.aspx[^],
http://www.pinvoke.net/default.aspx/user32.setcursorpos[^].

(Why using P/Invoke at all, when this functionality is available in System.Windows.Forms:
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx[^].

You could add a reference to this library to WPF application and set the cursor position using it. But, as far as I remember, I tried it out to find that it does not work in all cases. Why? As far as I remember, when the call of this API throws exception, the exception message clearly explains this problem. Sorry about being so vague in this matter, I just don't have time to repeat it right now. If you want to try, face the problem, and would need further explanation, I'll gladly try to explain it.)
Good luck,
—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900