tags:

views:

368

answers:

1

Right now when I try a loop that contains something like:

mouse_event(MOUSEEVENTF_MOVE,dx,dy,0,0);

The mouse tends to move more than (dx,dy). Researching this online, I think it's because of the acceleration applied by the operating system. How can I move the mouse an absolute amount?

MOUSEEVENTF_ABSOLUTE seems to maybe be what I'm looking for, but I can't see how to use it.

I've tried:

mouse_event(MOUSEEVENTF_ABSOLUTE || MOUSEEVENTF_MOVE,dx,dy,0,0);

but that doesn't work either. I'd prefer to use mouse_event rather than SetCursorPos or other methods, what should I do? Thanks.

+2  A: 

from winuser.h

#define MOUSEEVENTF_MOVE        0x0001
#define MOUSEEVENTF_ABSOLUTE    0x8000

MOUSEEVENTF_MOVE || MOUSEEVENTF_ABSOLUTE is the same thing as 0x0001 || 0x8001 which evaluates to true, which just happens to be 1!

Try it again with MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE and it will probably work.

Edit: after looking at the docs a bit, it appears that either you want MOUSEEVENTF_ABSOLUTE all by itself. or you need to account for the fact that the range of values it is looking for is 0-65535 scaled over the entire display.

If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.

John Knoeller
Okay, when I switch it to |, it just immediately moves the cursor to the (0,0) spot, even when I try mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE,100,100,0,0) for example
Dave61
added a hopefully relevant quote from the MS docs to my answer
John Knoeller