I'm creating some automation utils.
Part of it is automating mouse input.

I think I have my math wrong because the X coordidnate is incorrect at certain points for example is I give it x = 114 which should translate to 114 pixels from left of screen (0) it will not move there, and a few others.

Y is always correct.

here is code which I believe must be wrong math.

int SCREEN_WIDTH = GetSystemMetrics( SM_CXVIRTUALSCREEN );//correct
int SCREEN_HEIGHT = GetSystemMetrics( SM_CYVIRTUALSCREEN );//correct

MInput.dx = (x * (65536 / SCREEN_WIDTH));
MInput.dy = (y * 65536 / SCREEN_HEIGHT);

I've tried all kinds with my braces and casts and what not.
It's driving me mad.

Because not many people have access to this library, please could you specify some expected input and outputs?

Also, what is the data type of MInput?

I think I found answer on stackexchange, it appears to be solution.
But not certain if it is true of all screen resolutions.

Better use x * 0xFFFF / SCREEN_WIDTH + 1 for pixel-perfect coordinate normalization. (For all values of SCREEN_WIDTH < (0xFFFF / 2) and x <= SCREEN_WIDTH). Your formula can be tens of pixels off for common screen resolutions. – Kay Sarraute Sep 17 '13 at 14:17

http://stackoverflow.com/questions/7492529/how-to-simulate-a-mouse-movement

Are you calling SendInput like this:

    int screen_x = GetSystemMetrics( SM_CXVIRTUALSCREEN );
    int screen_y = GetSystemMetrics( SM_CYVIRTUALSCREEN );

    INPUT input = {0};
    input.type = INPUT_MOUSE;
    input.mi.dx = (x * 65535) / screen_x;
    input.mi.dy = (y * 65535) / screen_y;
    input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;

    UINT ret = SendInput( 1, &input, sizeof(INPUT) );

Almost.

    INPUT Input;
    SecureZeroMemory(&Input, sizeof(Input));
    MOUSEINPUT MInput;
    SecureZeroMemory(&MInput, sizeof(MInput));

    int SCREEN_WIDTH = GetSystemMetrics( SM_CXVIRTUALSCREEN );
    int SCREEN_HEIGHT = GetSystemMetrics( SM_CYVIRTUALSCREEN );

    MInput.dx = (x * 65536 / SCREEN_WIDTH + 1);
    MInput.dy = (y * 65536 / SCREEN_HEIGHT);
    MInput.mouseData = 0;
    MInput.dwFlags |= MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
    MInput.time = 0;
    MInput.dwExtraInfo = 0;
    Input.type = INPUT_MOUSE;
    Input.mi = MInput;

    if (SendInput(1, &Input, sizeof(Input))) {
        return 1;
    }

What I cannot find much info about is the dwExtraInfo member of MOUSEINPUT structure

I'd like to be able to control the speed of mouse movements, and I suspect this member is where the info needs to be, but there's very little I can find.

Anyone came across info more detailed than this...?

dwExtraInfo
Type: ULONG_PTR
An additional value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.

...with regards controling mouse speed?

Here's an excerpt from Introducing Windows 7 for Developers..

The Better Model: Enhancing the Touch Experience

The Better model addresses the need to make your application touch aware and provide better touch and multitouch support to your application than the default legacy support that was explained in the previous section. The Better model is focused on adding gestures support, as well as making other behavior and user interface (UI) changes so that applications are more touch friendly and go beyond simple gesture support.

To trace the origin of the input message, identify it as a touch-related message, and respond accordingly, the taskbar uses the GetMessageExtraInfo function. When your application receives a mouse message (such as WM_LBUTTONDOWN), it might call the Win32 API GetMessageExtraInfo function to evaluate whether the message originated from a pen or a mouse device. The value returned from GetMessageExtraInfo needs to be mask-checked against 0xFFFFFF0 and then compared with 0xFF515700. If the comparison is true, this mouse message was generated by a touch-sensitive device.

Thus, GetMessageExtraInfo is used essentially to distinguish between mouse input etc. and touch input such single and multiple gestures.

still cannot figure this out (speed of the movement)

I tried altering MInput.time = 0; to MInput.time = 1000; but that appears to turn my screen off :/

any info warmly welcomed.

Thank you for the tip BobS0327.

The above is good for setting what appears to be the mouse sensitivity as you would from control panel/mouse/pointer options.

Unfortunately, a simulated mouse movement is not bound by it as a manual operation is.

I'm beginning to think I might need to devise some algorythm to move the mouse incrementally to its destination.

Yay maths!
Not :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.