Jump to content

how to detect if the mouse DOES NOT MOVE ?


Recommended Posts

$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.

Link to comment
Share on other sites

  • 4 years later...

$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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...