Jump to content
Sign in to follow this  
benzmaster

how to detect if the mouse DOES NOT MOVE ?

Recommended Posts

benzmaster

Hi,

my question is simple, i'd like to click on a button if the mouse has not moved for 10 sec.

how could I detect that the mouse is NOT MOVING ?

Thx

Benzmstr

Share this post


Link to post
Share on other sites
jvanegmond

$lastMousePos = MouseGetPos()
$lastMouseMove = TimerInit()

While ( True )
    $curMousePos = MouseGetPos()
    If ( $lastMousePos[0] == $curMousePos[0] And $lastMousePos[1] == $curMousePos[1] ) Then
        If ( TimerDiff($lastMouseMove) > 10000 ) Then ; 10,000 ms = 10 seconds
            MsgBox(0, "", "Mouse hasn't moved for 10 seconds.")
        EndIf
    Else
        $lastMousePos = $curMousePos
        $lastMouseMove = TimerInit()
    EndIf
WEnd

This.

Share this post


Link to post
Share on other sites
benzmaster

Hughe Thanks !!

Bye

Share this post


Link to post
Share on other sites
noobieautolearn

$lastMousePos = MouseGetPos()
$lastMouseMove = TimerInit()

While ( True )
    $curMousePos = MouseGetPos()
    If ( $lastMousePos[0] == $curMousePos[0] And $lastMousePos[1] == $curMousePos[1] ) Then
        If ( TimerDiff($lastMouseMove) > 10000 ) Then ; 10,000 ms = 10 seconds
            MsgBox(0, "", "Mouse hasn't moved for 10 seconds.")
        EndIf
    Else
        $lastMousePos = $curMousePos
        $lastMouseMove = TimerInit()
    EndIf
WEnd

This.

I know it's been a while since you were around but maybe someone else can answer these questions.

1. In the statement While (True) does the (true) just tell it to go in an infinite loop until an endif statement is reached?

2. What is the purpose to "And $lastMousePos[1] == $curMousePos[1] ) Then"? If you already got the value for $lastMousePos and $curmousepos and you verified they are the same what purpose does the second verification serve?

3. What does it mean when you put a number in a bracket next to a variable? $lastMousePos[0] $lastMousePos[1]

Edited by noobieautolearn

Share this post


Link to post
Share on other sites
ileandros

I know it's been a while since you were around but maybe someone else can answer these questions.

1. In the statement While (True) does the (true) just tell it to go in an infinite loop until an endif statement is reached?

Read the help files for the While...WEnd function

Edit: You could use ExitLoop if you want to exit a loop function

2. What is the purpose to "And $lastMousePos[1] == $curMousePos[1] ) Then"? If you already got the value for $lastMousePos and $curmousepos and you verified they are the same what purpose does the second verification serve?

3. What does it mean when you put a number in a bracket next to a variable? $lastMousePos[0] $lastMousePos[1]

0 Returns the X co-ordinate as an integer.

1 Returns the Y co-ordinate as an integer.

Mouse moves from left to right and from up to down, or the opposite.

The x returns the one and the y returns the other.

You need to know both because x could change while y hasn't or y could change while x hasn't :D

Checking for both(x,y) can tell you if mouse has move or not

Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
noobieautolearn

Read the help files for the While...WEnd function

Edit: You could use ExitLoop if you want to exit a loop function

0 Returns the X co-ordinate as an integer.

1 Returns the Y co-ordinate as an integer.

Mouse moves from left to right and from up to down, or the opposite.

The x returns the one and the y returns the other.

You need to know both because x could change while y hasn't or y could change while x hasn't :D

Checking for both(x,y) can tell you if mouse has move or not

I have a question, am I right to assume that the way this works is that everything after the While (true) statement runs continuously and very fast and if you were theoretically able to move the mouse after the If ( $lastMousePos[0] == $curMousePos[0] And $lastMousePos[1] == $curMousePos[1] )and before it got to Else $lastMousePos = $curMousePos that after 10 seconds it would still display the message?

$lastMousePos = MouseGetPos()

$lastMouseMove = TimerInit()

While ( True )

$curMousePos = MouseGetPos()

If ( $lastMousePos[0] == $curMousePos[0] And $lastMousePos[1] == $curMousePos[1] ) Then

If ( TimerDiff($lastMouseMove) > 10000 ) Then ; 10,000 ms = 10 seconds

MsgBox(0, "", "Mouse hasn't moved for 10 seconds.")

EndIf

Else

$lastMousePos = $curMousePos

$lastMouseMove = TimerInit()

EndIf WEnd

Edited by noobieautolearn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×