You can use events to signal when a condition is true.

In this example, we use events to coordinate the execution of two jobs.
What we are after is a program that will send a series of keystrokes to an application then 10 seconds later send a different series of keystrokes. This program then repeats.

## Event test
# Description: This job trio uses the WinCron event to control the frequency of keys
# sent using sendKeys. In this example, we want to send some keystrokes, then 10 seconds
# later, send some more keystrokes.
# The first job runs once only to launch notepad.exe and clear the event.
# the second job checks an event before sending some keystorkes to notepad
# the third job clears an event, then sends keystrokes to notepad.

## sendkeys_main
# Description: run once program to:
# 1. launch notepad.exe
# 2. clear event (my_semaphore)
{
-name sendkeys_main
-start
-command notepad.exe
-action -clearEvent my_semaphore
-stop
}

## sendkeys_pass1
# Description: if the event is set, this job will 'break' and not execute any further statements.
# If this event is not set, this job will set the event and do whetever processing is required.
# This job rechecks the event every second.
{
-name sendkeys_pass1
-start -delay 0 0 0 5

# if my_semaphore is set, we're still waiting
-action -onerror break
-action -checkEvent my_semaphore
-action -setEvent my_semaphore

# setup error handler
-action -onerror operation_fail

# find the window - exception if not found
-action -findWindow hwnd "Untitled.*" _

# set the foreground window - exception on error
-action -setForegroundWindow hwnd

# type some text
-action -sendkeys sendkeys "pass1, "

-action -inc 0 0 0 1
}

## sendkeys_pass2
# Description: This job fires 10 seconds after pass1 and clears the event.
# after clearing the event, this job does whatever processing is necessary.
# Clearing the event will allow pass1 to run.
{
-name sendkeys_pass2
-start -delay 0 0 0 15

# clear semaphore so pass1 can run
-action -clearEvent my_semaphore

# setup error handler
-action -onerror operation_fail

# find the window - exception if not found
-action -findWindow hwnd "Untitled.*" _

# set the foreground window - exception on error
-action -setForegroundWindow hwnd

# type some text
-action -sendkeys sendkeys "pass2, "

-action -inc 0 0 0 10
}

# operation failed
{
-name operation_fail
-action -print SendKeys test failed with error:
-action -print %TG.LAST_ERROR%
-action -return break
}
_________________________
Regards,
Luke Tomasello