SRL Archive - Delphi/FPC Help and Tutorials

Moving the mouse...


Jason2gs

2007-08-09 13:58:34

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

2007-08-09 23:52:38

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

2007-08-10 09:05:49

No clue :S Maybe you should ask freddy?

Smartzkid

2007-08-10 09:20:34

Add the client window's screen position to the coordinates you want to move the mouse to?

Jason2gs

2007-08-10 11:16:47

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

2007-08-10 11:48:28

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

2007-08-10 12:18:27

Ty Spky :)

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

Spky

2007-08-10 12:23:38

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

2007-08-10 13:48:33

Awesome, Thanks :)

Easier than I thought it was gonna be.