Countdown using a handler

Asked by _elgato

Since I can not make observe() work on Windows 7, could I make a script that every 10 mins stops it normal task an executes a handler?

Like:

def handler(e):
     click("image-path")

while (1):
   wait(30)
   click("image-path")

   if (countdown_from_10 = 0):
      handler

The original script is a little more complicated than that but it is esentially what I want to do: every 10 mins a handler is executed, what do I need to make the timer?

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
_elgato
Solved:
Last query:
Last reply:
Revision history for this message
Mike Lee (m-lee) said :
#1

Do you really want to hang this code in an infinite loop ?

def ten_minutes_since (time_then) :
  time_now = time.time()
  if time_now > time_then + 600 :
    time_then = time_now
    return (True)
  else:
    return (False)

time_then = time.time()
while (1):
  if ten_minutes_since(time_then) :
    print "Click something"
  else:
    sleep(1)
    print "Still waiting.."

Revision history for this message
_elgato (el-gato-negro-v) said :
#2

Thanks, I'll try that.

Yes, in fact the main purpouse of the script is to click a button every 30 seconds, the second task triggers every 10 mins. It's a very simple task but very very repetitive that's why I made a script for it.

Ok, I'm going to try your script now and put the question as answered, I'll come back if I can make it.

Thanks, again!

Revision history for this message
RaiMan (raimund-hocke) said :
#3

you need an import time in the first line of your script.