BSmit Posted October 23, 2013 Posted October 23, 2013 Hello autoIT experts, Im new to AutoIT and trying to make a script that starts notepad.exe when there isnt any user activity on our Windows7 PC for like 3 minutes Problem is that the script keeps starting notepad (until i for example hit the ENTER button) Hope someone can help
satanttin Posted October 23, 2013 Posted October 23, 2013 Think no one can help you without posting a piece of code
BSmit Posted October 23, 2013 Author Posted October 23, 2013 (edited) thank you for your reply Satanttin My code so far ..: #include <Constants.au3> #include <winapiex.au3> local $count_down = 5 * 60 * 100 local $old_idle_time = 0, $secs, $mins, $diff while 1 sleep(1000) ; idle for a sec if $old_idle_time > _winapi_getidletime() then $old_idle_time = _winapi_getidletime() if _winapi_getidletime() > $count_down then ; run("notepad.exe") ;exit ; endif $diff = int( $count_down - _winapi_getidletime() ) $secs = int(Mod($diff, 60000)/1000) $mins = Mod(Int($diff / 60000), 60) wend Edited October 23, 2013 by BSmit
BSmit Posted October 23, 2013 Author Posted October 23, 2013 i think i need to use something like this : http://www.autoitscript.com/autoit3/docs/keywords/ExitLoop.htm Or maybe "DO .....Until" Playing with some examples from this site
kylomas Posted October 24, 2013 Posted October 24, 2013 BSmit, Try this...I think you need to generate an event that restarts the idle time counter (mouse move in this example) #include <Constants.au3> #include <winapiex.au3> #include <date.au3> local $count_down = 5000 ; 5 seconds local $mpos ConsoleWrite('start while loop at ' & _now() & @LF) while 1 sleep(1000) ; idle for a sec if _winapi_getidletime() > $count_down then ; generate an event to reset getidletime $mpos= mousegetpos() mousemove($mpos[0]+1,$mpos[1]+1) ConsoleWrite('running notepad at ' & _now() & @LF) run("notepad.exe") endif wend Watch the console for timings... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
BSmit Posted October 24, 2013 Author Posted October 24, 2013 Hi Kylomas, I compiled your version of the script but it also keeps starting notepad.exe
kylomas Posted October 24, 2013 Posted October 24, 2013 BSmit, Yes, it does the same on my system when compiled, but not when run through SCiTE... I changed it to move the mouse 10 pixels, compiled it and now it works... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
BSmit Posted October 24, 2013 Author Posted October 24, 2013 Thank you ! im gonna try it right now quickly
BSmit Posted October 24, 2013 Author Posted October 24, 2013 BSmit, Yes, it does the same on my system when compiled, but not when run through SCiTE... I changed it to move the mouse 10 pixels, compiled it and now it works... kylomas Sorry i must over look something, can you please show me what you changed in the source ?
kylomas Posted October 24, 2013 Posted October 24, 2013 #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=qq.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Constants.au3> #include <winapiex.au3> #include <date.au3> local $count_down = 5000 ; 5 seconds local $mpos ConsoleWrite('start while loop at ' & _now() & @LF) while 1 sleep(1000) ; idle for a sec if _winapi_getidletime() > $count_down then ; generate an event to reset getidletime $mpos= mousegetpos() mousemove($mpos[0]+1,$mpos[1]+10) ConsoleWrite('running notepad at ' & _now() & @LF) run("notepad.exe") endif wend Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
BSmit Posted October 24, 2013 Author Posted October 24, 2013 Thank you - compiled your version but it has the same behaviour here: - It starts notepad.exe after 6 secs and then starts it again 5 secs later, and then again ...( but i just want to start notepad.exe once after 5 secs)
kylomas Posted October 24, 2013 Posted October 24, 2013 (edited) BSmit, In that case all you need is this... local $count_down = 5000 ; 5 seconds ConsoleWrite('start while loop at ' & _now() & @LF) while 1 sleep(1000) ; idle for a sec if _winapi_getidletime() > $count_down then run("notepad.exe") exitloop endif wend kylomas edit: apologies,I mis-read your original post! Edited October 24, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
BSmit Posted October 24, 2013 Author Posted October 24, 2013 Exactly! you are right , the only problem with Exitloop is , is that it closes the whole script. when the system is idle for like 5 secs , it starts notepad.exe (and only once) but it also 'kills' the script itself. Im trying to make a script that A) starts notepad.exe when the system is idle (for 5 secs). when the input is back, it (the scripts basically "waits" until its idle again for 5 secs , then starts notepad.exe (once) Thank you for your fast replies!
JohnOne Posted October 24, 2013 Posted October 24, 2013 Is this thread for real? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
BSmit Posted October 24, 2013 Author Posted October 24, 2013 (edited) yes Im experimenting with AutoIT and im just trying to make a script that runs a program when there isnt any user activityfor a certain amount of time It works great so far, only problem is, is that it keeps running the program until the user moves the mouse...(and my goal is to run the program once, until the user moves the mouse) Edited October 24, 2013 by BSmit
kylomas Posted October 24, 2013 Posted October 24, 2013 BSmit, User activity refers to a mouse or keyboard event...what you just described is exactly what the script in post #10 does... You have enough code to go on, try something and get back to us if you run into problems... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
BSmit Posted October 24, 2013 Author Posted October 24, 2013 Hi Kylomas, The code in post #10 keeps starting new instances of notepad.exe while the system is Idle i added "msgbox($mb_ok,'test','test ok') underneath run("notepad.exe") and now it starts notepad.exe only once but the user has to click the messagebox
kylomas Posted October 24, 2013 Posted October 24, 2013 The code in post #10 keeps starting new instances of notepad.exe while the system is Idle Which is what you asked for here... A) starts notepad.exe when the system is idle (for 5 secs). when the input is back, it (the scripts basically "waits" until its idle again for 5 secs , then starts notepad.exe (once) Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
BSmit Posted October 24, 2013 Author Posted October 24, 2013 (edited) sorry, then i wasn't clear .... i really just want to run notepad.exe once and when the input is back , the script "waits" until the system gets idle again im trying all kinds of things and keep ya guys up2date Edited October 24, 2013 by BSmit
kylomas Posted October 24, 2013 Posted October 24, 2013 (edited) when the input is back meaning that you want to wait on the NotePad??? if so just change the run to runwait Edited October 24, 2013 by kylomas BSmit 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
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