In the below codes, it is expected my mouse cursor would be set to (100,100) on the screen. However, it turns out the cursor is moved to (2,1).
And when MOUSEEVENTF_ABSOLUTE
is not set, I expected the mouse would move 100 pixels to the right and bottom respectively. While the result is it moved from (352, 65) to (670, 383).
INPUT Input[1];
ZeroMemory(Input, sizeof(INPUT) * 1);
Input[0].type = INPUT_MOUSE;
Input[0].mi.dx = 100;
Input[0].mi.dy = 100;
Input[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
SendInput(1, Input, sizeof(INPUT));
Posts I have read:
I have realized that there is another post about the similar situation. But I suspect whether memory leak is the answer since I used cout
to check the value of Input[0].mi.dx
and Input[0].mi.dy
and they are exact 100
.
From the solution of the top voted post in here, factors are used to modify the xy values. Even so, the result is not accurate to your input. And the answer did not explain why a factor need to be used.
My question:
1) What is the accurate way to move cursor in Windows beside using SetCursorPos()
? (there is a reason I don't want to use it)
2) Does anyone knows the reasons behind the unreasonable movement with MOUSEEVENTF_MOVE
?