View Full Version : Moving the mouse...


Jason2gs
08-09-2007, 05:58 PM
I'm having a bit of trouble moving the mouse.

I can move the mouse just fine, but it doesn't recognize the active window's boundaries.

Meaning... I tell it to move the mouse to the form's upper-left corner (0, 0), but it moves it to to the Screen's upper-left corner. Help?

Also, what's the best command to use to move the mouse?

So far I've found:

SetCursorPos(X, Y);

Mouse.CursorPos := TPoint;

and

Mouse_Event(MOUSEEVENTF_MOVE, TPoint.X, TPoint.Y, 0, GetMessageExtraInfo);

Are there any differences between the three?

Bobarkinator
08-10-2007, 03:52 AM
Sounds like the first is MoveMouse. You should try reconstructing the mouse procedure from SRL in Delphi. It would be great experience.

Anyways, I have no clue about your problem. I'm guessing the SetClientWindowHandle is native to SCAR? Or did it come directly from Delphi?

GoF
08-10-2007, 01:05 PM
No clue :S Maybe you should ask freddy?

Smartzkid
08-10-2007, 01:20 PM
Add the client window's screen position to the coordinates you want to move the mouse to?

Jason2gs
08-10-2007, 03:16 PM
I guess I could do that. Mark where the client's position is in relation to the rest of the screen. I'd hate to bug Freddy about this :)

Spky
08-10-2007, 03:48 PM
Get the wanted windows coords with
function GetWindowRect(HWnd : LongInt; var Rect : TRect)

You could use ClientToScreen.

Is it your form you are navigating around, or another window?

Jason2gs
08-10-2007, 04:18 PM
Ty Spky :)

It's my form, and what exactly does ClientToScreen do?

Spky
08-10-2007, 04:23 PM
You need only use ClientToScreen. It just calculates the coords so MoveMouse(0, 0) will move to your forms Top, Left instead of the screens.

procedure MoveMouse(x, y: Integer) ;
var
Point: TPoint;
begin
Point:= ClientToScreen(Point(x, y)) ;
SetCursorPos(Point.x, Point.y) ;
end;

Jason2gs
08-10-2007, 05:48 PM
Awesome, Thanks :)

Easier than I thought it was gonna be.