how to simulate mouse movement in a game?

I did this code:

void MouseMove (int x, int y )
{
double fScreenWidth=::GetSystemMetrics( SM_CXSCREEN )-1;
double fScreenHeight::GetSystemMetrics( SM_CYSCREEN )-1;
double fx = x*(65535.0f/fScreenWidth);
double fy = y*(65535.0f/fScreenHeight);
INPUT Input={0};
Input.type=INPUT_MOUSE;
Input.mi.dwFlags=MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
Input.mi.dx = fx;
Input.mi.dy = fy;
::SendInput(1,&Input,sizeof(INPUT));
}

This code work, but if i start to play it doesn't work
Check the return value from SendInput.
I suspect that it will only work when the mouse is inside your window.
It work in the game menu, when there is the cursor, but if i start to play and the cursor disappears it's doesn't work
There is only one mouse for the whole system. If the mouse is inside your window the mouse "belongs" to your program and you can move it.
If the mouse if outside your window it means the mouse "belongs" to a other program and so you can't move/hide it.
No, it works, just need to remove |MOUSEEVENTF_ABSOLUTE
Topic archived. No new replies allowed.