SRL Archive - OSR Help

Mouse


Death12652

2011-04-20 21:57:41

Is there a way to check if the mouse is moving?

NCDS

2011-04-20 22:02:03


function IsMouseMoving: Boolean;
var
x, y, x2, y2: Integer;
begin
GetMousePos(x, y); //Get mouse position
Wait(10); //Wait 10 ms
GetMousePos(x2, y2); //Get mouse position to compare to
Result := (x2 <> x) or (y2 <> y); //if x or y coord is different mouse is moving
end;
Not the greatest but it would work.

KingKong

2011-04-21 00:48:29

^It won't work with smart, since mmouse/mouse has to be finished and then your code must be run, by which time the mouse would've stopped moving, but it will if you select the rs client and use the actual mouse.

Smartzkid

2011-04-21 01:18:09

From: KingKong
^It won't work with smart, since mmouse/mouse has to be finished and then your code must be run, by which time the mouse would've stopped moving, but it will if you select the rs client and use the actual mouse.


You shouldn't have any reason to check if the mouse is moving from within the script that's moving the mouse?

KingKong

2011-04-21 04:33:46

From: Smartzkid
You shouldn't have any reason to check if the mouse is moving from within the script that's moving the mouse?


I see no reason to check if a mouse if moving at all, but i was just pointing out that it won't work with smart, and also if the mouse is moving then shouldn't someone be moving it? and if so then it should be pretty obvious that its moving.

Kasi

2011-04-21 04:46:21


Var
FT : Boolean; // global

function IsMouseMoving: Boolean;
var
x, y, x2, y2: Integer;

begin
If Not FT Then
Begin
GetMousePos(x, y); //Get mouse position
FT := True;
Exit;
End;
GetMousePos(x2, y2); //Get mouse position to compare to
Result := (x2 <> x) or (y2 <> y); //if x or y coord is different mouse is moving
FT := False;
end;
// no need for the wait anymore.

there is a way around this. if there was a check to see if the function had already been run once. however the whole function will have to be run twice.
so


Begin
IsMouseMoving;
MMouse(34, 45, 5, 5);
WriteLn(+BoolToStr(IsMouseMoving));
End.
Havent compiled anything here so idno if it'll run without errors.

KingKong

2011-04-21 04:52:34

^Just a little flaw in your code:
You can't edit global variables like that, and i don't know if pascalscript allows it(if it does i don't know how to implement it)

masterBB

2011-04-21 05:57:43

From: KingKong
^Just a little flaw in your code:
You can't edit global variables like that, and i don't know if pascalscript allows it(if it does i don't know how to implement it)


What makes you think you can't. I edit all my global vars like that…

edit:
you were probably pointing towards his use of the x,y vars. Yes, that shouldn't be done like this.

Var
prevPoint:TPoint = Point(0,0);

function IsMouseMoving: Boolean;
var
x, y: Integer;

begin
If Not(prevPoint = Point(0,0)) Then
Begin
GetMousePos(x, y); //Get mouse position
prevPoint := Point(x,y);
Exit;
End;
GetMousePos(x, y); //Get mouse position to compare to
Result := not(prevPoint = Point(x,y));
prevPoint := Point(0,0);
end;

Rich

2011-04-21 06:20:51

You could check if the mouse has moved, but not if it's moving. For that we'd need multi-threading.

Death12652

2011-04-21 08:57:34

Its for a personal use not for smart :D thanks.