-
July 16th, 2017, 05:46 PM
#1
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'.
-
July 16th, 2017, 07:07 PM
#2
Re: Simulate cursor ( mouse ) movement
Use a loop and move the cursor in small increments until it reaches its destination.
-
July 18th, 2017, 04:41 PM
#3
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 ??
-
July 19th, 2017, 08:57 AM
#4
Re: Simulate cursor ( mouse ) movement
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").
-
July 20th, 2017, 06:13 PM
#5
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.
Last edited by Rabelo; July 20th, 2017 at 06:15 PM.
Reason: error
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|