Simulate cursor ( mouse ) movement
Code:
int x = 100;
int y = 100;
SetCursorPos(x,y);
Sleep(2000);
SetCursorPos(x+100,y+200);
This code sets cursot to one dot, after 2 seconds to another dot.
However cursor just "teleporting".
And I want to make cursor to "walk" from one dot to another, not just "teleport".
Its kinda like demonstration. Cursor should stay visible ( and it is ), i simply want to make 'travelling route'.
Re: Simulate cursor ( mouse ) movement
Use a loop and move the cursor in small increments until it reaches its destination.
Re: Simulate cursor ( mouse ) movement
I expected advanced variant, but ok. I made as you suggest already.
I have extra question, it is related.
Code:
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
What 3rd and 4th parameter require? Is it for X-Y-Z asis ??
Re: Simulate cursor ( mouse ) movement
Quote:
Originally Posted by
programm
I expected advanced variant, but ok. I made as you suggest already.
I have extra question, it is related.
Code:
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
What 3rd and 4th parameter require? Is it for X-Y-Z asis ??
You may have expected code, but putting the code you have in a loop is trivial, and if you are asking for such code, it might be a better exercise for you to do yourself.
For the mouse_event api question there is the official Microsoft msdn documentation: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
Note that the mouse_event api is deprecated and that the SendInput api should be used instead. SendInput msdn documentation can be found at https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
Code snippets for both API's can be found in bing or google by searching for "SendInput examples" (or "mouse_event examples").
Re: Simulate cursor ( mouse ) movement
You could also:
1- stablish a timer event at 1/15s (for example)
2- at every time this event is hit you call SetCursorPos with the new values
This way you won´t block the aplication in the loop.
If the movement is a line you can calculate dx and dy values before set the timer and increment the mouse positions at avery time the timer is hit with these values.
If the movement is not a line, a parabola for example, you will have to calculate every position when the timer is hit. Remember that the dt (time lapse) is constant so this will not be dificult to calculate the new position.