i wish to move the mouse cursor to the bottom right corner of an application window
but for some reason (my problem) it moves way over to the bottom right corner of the screen
in pwi->rcClient.right i get almost 800
and in pwi->rcClient.bottom i get almost 600
(tried getting the cords with GetClientRect() also but i get the same width and height as the right and bottom cords from GetWindowInfo() - so it might be in the cursor moving)
while i manually looked for the correct cords and it was some thing like right=500 and bottom=400
here is my code
sendUserInput() is just a wrapper for SendInput()
1 2 3 4 5 6 7 8 9 10 11 12
PWINDOWINFO pwi=new WINDOWINFO;
LONG cursorX,cursorY;
pwi->cbSize=sizeof(WINDOWINFO);
GetWindowInfo(hwnd,pwi);
cursorX=pwi->rcClient.right;
cursorY=pwi->rcClient.bottom;
//move cursor to top left corner of the screen
sendUserInput(INPUT_MOUSE,-1000,-1000,0,MOUSEEVENTF_MOVE,0,0);
sendUserInput(INPUT_MOUSE,cursorX,cursorY,0,MOUSEEVENTF_MOVE,0,0);
all ideas are welcome
thank you for your time and thought
Tal
That function looks right (although I wouldn't have bothered to use new to dynamically create a new input struct - I would have just used a local variable).
However, how the SendInput functions uses the parameters is a bit tricky.
If Flags is just MOUSEEVENTF_MOVE on it's own, then it is a relative move. In other words,
the mouse will be moved dx, dy pixels from it's current position.
So you would need to do a system call GetCursorPos function to get the current cursor position and do a simple bit of math to calulate this relative move.
if you include MOUSEEVENTF_ABSOLUTE as part of the flags like this@: Flags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, then that says move the mouse
to the absolute position given in dx and dy.
However, this absolute positioning using a cordiante system where 0,0 id top left of the screen and the bottom right of the screen is 65535,65535.
The window values you got from the GetWindowInfo function is in actual screen pixels - sou you would have to convert/scale from pixels to absolute co-ords.
This would require a couple of system calls to get the screen resolution.
lets say you screen resolution is 1280 x 1024.
The X scale factor would be 65535/1280 = 51.19
The Y scale factor would be 65535/1024 = 63.99
So you would have to multiply the values you got from the GetWindowInfo function by these values to do an absolute cursor move.
So you can see - it is much easier to use the SetCursorPos function than the SendInput function