benzmaster Posted February 4, 2009 Share Posted February 4, 2009 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 Link to comment Share on other sites More sharing options...
jvanegmond Posted February 4, 2009 Share Posted February 4, 2009 $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. taypatte 1 github.com/jvanegmond Link to comment Share on other sites More sharing options...
benzmaster Posted February 4, 2009 Author Share Posted February 4, 2009 Hughe Thanks !! Bye Link to comment Share on other sites More sharing options...
noobieautolearn Posted March 3, 2013 Share Posted March 3, 2013 (edited) $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 March 3, 2013 by noobieautolearn Link to comment Share on other sites More sharing options...
ileandros Posted March 3, 2013 Share Posted March 3, 2013 (edited) 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 Checking for both(x,y) can tell you if mouse has move or not Edited March 3, 2013 by ileandros I feel nothing.It feels great. Link to comment Share on other sites More sharing options...
noobieautolearn Posted March 3, 2013 Share Posted March 3, 2013 (edited) 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 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 March 3, 2013 by noobieautolearn Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now