tags:

views:

386

answers:

2

It's been yonks since I've done any VB6...

I need to take control of the mouse pointer and move it smoothly between two points.

Is the best way to do this a combination of GetCursorPos, SetCursorPos and a timer or two, or is there a better way?

Thanks for any help.

+1  A: 

Using SetCursorPos with a timer to move the cursor between two points sound like the most sensible way to me. (Why would you need to use GetCursorPos even?)

Were you hoping for another solution in particular? You're certainly not going to be able to perform this task without the WinAPI, but there may be another function that does what you want.

Noldorin
@Noldorin - thanks, I think I will need GetCursorPos as the new cursor location needs to be set relative to the current location. I just thought there may be some other call that I could have used that would take care of the smoothness between points. Maybe wishful thinking.
Galwegian
@Galwegian: No problem. And yeah, fair enough about the use of GetCursorPos. There may be some function that can move the cursor around smoothly, but I haven't encountered it in all my poking around the WinAPI. Simple linear interpolation with time should do the job quite well. :)
Noldorin
+1  A: 

As noted, Get/SetCursorPos with a timer is the ticket. It's worth experimenting with timer periods and position deltas to get the largest of each that does things as smoothly as you require, but not more.

Separate the deltas for X and Y, figure which moves the greater distance, and use Bresenham to draw the invisible line between the points.

A naive solution might move the cursor more than once per video refresh, for example, or fewer than 4 pixels per step, which would be a waste of time.

Bresenham is probably overkill for this task, since using floating point values and just rounding them off probably won't be a big issue for the OP.
Noldorin
(Though it would of course work perfectly fine.)
Noldorin