Jump to content

Loop keeps starting notepad.exe


BSmit
 Share

Go to solution Solved by BSmit,

Recommended Posts

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

#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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

B) 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!

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

B) 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

Link to comment
Share on other sites

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 by BSmit
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...