dangbeau Posted October 29, 2015 Share Posted October 29, 2015 (edited) Is there any way the script stop running by itself when it figures out someone using the mouse? Since the script is auto clicking and I want it stop automatically when someone use my pc while i'm away. Edited October 29, 2015 by dangbeau Link to comment Share on other sites More sharing options...
jdelaney Posted October 29, 2015 Share Posted October 29, 2015 (edited) You don't need to run your scripts on the desktop. You can run it on the service level (session 0), and then not worry about any user messing it up.There is a function=_Timer_GetIdleTime, but your script will trigger it (if it sends keys or moves the mouse), so the user action wouldn't matter. But you could do adlibregister with that function, and if the timer resets, then sleep until the timer goes over some set amount of time. Edited October 29, 2015 by jdelaney dangbeau 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
TheSaint Posted October 30, 2015 Share Posted October 30, 2015 There are several ways to do this, but the simplest might be to use BlockInput and stop anyone else using your PC altogether until a Hotkey is clicked. Be sure you read up on BlockInput though, as you don't want to block that Hotkey. As for the Hotkey, look at the _IsPressed command .... making sure you use the DLL version for repeated calls/checks on a regular basis.Another method is to regularly check your mouse position.Personally, I would combine all the above ... both enabling and disabling BlockInput at key moments, providing window of opportunity pauses perhaps. You really do not want an auto-click to go astray.BE CAREFUL with BlockInput. dangbeau 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 30, 2015 Moderators Share Posted October 30, 2015 @dangbeau it would also help to know what you're trying to accomplish. In all likelihood you could get away from using the mouse if you employ the Control commands. Then it wouldn't matter as much if someone moved the mouse. dangbeau 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
jdelaney Posted October 30, 2015 Share Posted October 30, 2015 Another thought. If you are interacting with a specific window, then you can create an AdLibRegister to call a function to sleep if that window is not active.So if a user clicks into a new window, your script will sleep until your window is active again. dangbeau 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
JohnOne Posted October 30, 2015 Share Posted October 30, 2015 (edited) Here is a simple but effective way of doing that. It's based on knowing where the mouse clicks, which you obviously do, seeing as how you wrote the code.In the example the array of expected mouse positions is hard coded, you can change them as you wish if your script has dynamic positions. Please try to figure out how, for yourself. (hint: you should only need two entries in array, where the mouse is, and where it is going to be next)Global $aMousePositions[3][2] $aMousePositions[0][0] = 200 $aMousePositions[0][1] = 200 $aMousePositions[1][0] = 300 $aMousePositions[1][1] = 300 $aMousePositions[2][0] = 400 $aMousePositions[2][1] = 400 HotKeySet("{Esc}", "_Exit") AdlibRegister("_CheckUserMovedMouse") While 3 For $i = 0 To UBound($aMousePositions) - 1 MouseMove($aMousePositions[$i][0], $aMousePositions[$i][1], 0) Sleep(1000) Next WEnd Func _CheckUserMovedMouse() Local $aMousePos = MouseGetPos() For $i = 0 To UBound($aMousePositions) - 1 If ($aMousePos[0] = $aMousePositions[$i][0] And $aMousePos[1] = $aMousePositions[$i][1]) Then Return ; Mouse is one of your predefined positions; EndIf Next MsgBox(0, "User Active", "Exiting") ; Someone moved mouse. Exit EndFunc ;==>_CheckUserMovedMouseEDIT: Obviously I used Move instead of Click, for demonstration purpose. Edited October 31, 2015 by JohnOne dangbeau 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jdelaney Posted October 31, 2015 Share Posted October 31, 2015 (edited) Since JohnOne was so kind to give an example, I modified it for my thought as well #include <WinAPI.au3> $iPid = Run("Notepad.exe") Sleep(2000) HotKeySet("{Esc}", "_Exit") AdlibRegister("_PauseIfProcessWinNotActive",500) Func _PauseIfProcessWinNotActive() Local $iTempPid _WinAPI_GetWindowThreadProcessId(WinGetHandle("[ACTIVE]"),$iTempPid) While $iTempPid <> $iPid ConsoleWrite("I'm sleeping!!" & @CRLF) Sleep(1000) _WinAPI_GetWindowThreadProcessId(WinGetHandle("[ACTIVE]"),$iTempPid) WEnd ConsoleWrite("I'm not sleeping!!" & @CRLF) EndFunc ;==>_CheckUserMovedMouse Func _Exit() Exit EndFunc ; this will actually be your script: While True WEndAs long as the notepad started...or some window spawned from that process (such as a save as window) is active, the console will output "I'm not sleeping!!"...make anything else active, then you will see console output "I'm sleeping!!"If you are working with multiple PIDs then you can create an array, and keep adding to it as you create them...then in the adlib func, loop through that array and see if the temppid matches anything in the array (loop through the array)... Edited October 31, 2015 by jdelaney dangbeau 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
dangbeau Posted October 31, 2015 Author Share Posted October 31, 2015 wow, very detailed. Thank you so much guys <3 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