Macro Scheduler 15

OnEvent

OnEvent>EventType,EventParm,ExtraParm,Subroutine

 

Not supported in Macro Scheduler Lite.

 

Establishes an event handler.  When the event occurs the script branches to the specified Subroutine.

 

Event Types:

 

EventType

EventParm

ExtraParm

Description

WINDOW_OPEN

Window_Title

WF_TYPE

Triggers when specified window is open.

See IfWindowOpen for window title & WF_TYPE syntax.

WINDOW_NOTOPEN

Window_Title

WF_TYPE

Triggers when specified window is closed.

See IfWindowOpen for window title & WF_TYPE syntax.

WINDOW_NEWACTIVE

0

0

Triggers when the foreground window changes.

FILE_EXISTS

Filename

0

Triggers when the specified file exists.

FILE_NOTEXISTS

Filename

0

Triggers when the specified file does not exist.

KEY_DOWN

Key/KeyCode

Modifier

Triggers when the key is down.  See WaitKeyDown

KEY_UPKey/KeyCode0Triggers when the key is up. See WaitKeyDown for VK codes. Added in v15.0.11

DIALOG_EVENT

Dialog Name

Modal Result

Triggers when dialog's modal result matches
e.g. when a button is pressed.

DIALOG_CHANGE

Dialog Name

Object Name

Triggers when object value is changed.

PROCESS_EXISTS

Process Name


Triggers when specified process exists.

PROCESS_NOTEXISTS

Process Name


Triggers when specified process does not exist.

PIXEL_COLOR

x:y

color_code

Triggers when color at specfied x,y position matches.

DATE

Date in YYYYMMDD format


Triggers when current date matches given date.

TIME

Time in HHMM format


Triggers when current time matches given time

WINDOWS_SHUTDOWN0delay_secondsTriggers when a Windows shutdown request is detected.

CUSTOM

SubroutineName

VariableName

Custom Trigger - runs given subroutine periodically and triggers when specified variable = TRUE

 

Explanations:

 

WINDOW_OPEN and WINDOW_NOTOPEN

EventParm takes a window title (or handle if WIN_USEHANDLE has already been set to 1).

ExtraParm takes a WF_TYPE value.  See SetFocus and IfWindowOpen for explanation.

 

By definition these event types cause the script to continually enumerate and loop through the list of windows open on the system. This is an intensive process and you may therefore see CPU usage increase.  For most people this is not a problem. However, if you wish to reduce CPU usage you can set WIN_SLEEP to 1 at the expense of processing time (in theory setting WIN_SLEEP to 1 will slow the checks down while reducing CPU usage).

 

WINDOW_NEWACTIVE

EventParm and ExtraParm are not used.  Set to zero.

 

FILE_EXISTS and FILE_NOTEXISTS

EventParm takes a filename.

ExtraParm is not used.  Set to zero.

 

KEY_DOWN

EventParm takes a character for an ordinary key.  For other keys use the virtual key code preceeded by VK.  See WaitKeyDown for more information.

ExtraParm is used to specify a modifier key:

 

0: No modifier key

1: SHIFT key must also be pressed

2: CONTROL key must also be pressed

3: ALT key must also be pressed

4: SHIFT + ALT keys must be pressed

5: CONTROL + ALT keys must be pressed

6  SHIFT + CONTROL keys must be pressed

7: CONTROL + ALT + SHIFT keys must also be pressed

8: Windows key must also be pressed

 

DIALOG_EVENT

EventParm is the dialog name.  ExtraParm is a modal result value to detect.  This could be the modal result of a button or menu option.  So when that button is pressed the subroutine is triggered.

 

DIALOG_CHANGE

EventParm is the dialog name.  ExtraParm is the object name.  When the value of the object is changed by the user the subroutine is triggered.  Valid object types include Edit, Memo, ComboBox, ListBox, RadioGroup and CheckBox.

 

PIXEL_COLOR

EventParm should have the format X:Y where X and Y are the x and y positions of the screen coordinate and should be separated by a colon.  ExtraParm is the color code to watch for.  Use the cursor monitor in the editor to determine the desired color code.

 

DATE

EventParm takes a date in YYYYMMDD format.

 

TIME

EventParm takes an hour in HHMM format (24 hour format).


WINDOWS_SHUTDOWN

ExtraParm can be set to the number of seconds Windows shutdown should be delayed, or zero. This is to allow time for your event subroutine to run. Try to keep this short.

 

CUSTOM

Allows to create any kind of event trigger.  EventParm is a subroutine which will be executed continually.  ExtraParm is a variable name.  When the variable name becomes TRUE the trigger is fired.  See example below which creates a trigger based on a registry value.

 

To disable an event handler issue the same OnEvent code but with the subroutine omitted (i.e. an empty string).

 

Abbreviation: ONE

 

Example

 

OnEvent>WINDOW_OPEN,Notepad*,2,DoNotepad
OnEvent>WINDOW_NOTOPEN,Notepad*,2,DoNotepadNotOpen
OnEvent>WINDOW_NEWACTIVE,0,0,DoNewWindow
OnEvent>KEY_DOWN,VK32,3,KeyPress

OnEvent>CUSTOM,MyTriggerSub,DoIT,DoSomething
 
Label>start
  Wait>1
  If>NotepadOpen=1
    Message>Notepad is open
  Else
    Message>Notepad is not open
  Endif
Goto>start
 
SRT>DoNotepad
  Let>NotepadOpen=1
END>DoNotepad
 
SRT>DoNewWindow
  GetActiveWindow>title,x,y
  MessageModal>New window: %title%
END>DoNewWindow
 
SRT>DoNotepadNotOpen
  Let>NotepadOpen=0
END>DoNotepadNotOpen
 
SRT>KeyPress
  MessageModal>ALT+Space was pressed
END>KeyPress

 

SRT>MyTriggerSub

  //This custom trigger monitors a registry key value

  RegistryReadKey>HKEY_CURRENT_USER,Software\MySoft,MyValue,res

  If>res=FIRE

    Let>DoIT=TRUE

  Endif

END>MyTriggerSub

 

SRT>DoSomething

  //reset the registry key and do something

  RegistryWriteKey>HKEY_CURRENT_USER,Software\MySoft,MyValue,IDLE

  //do something else

  Let>DoIT=FALSE

END>DoSomething

 

To disable an event handler call OnEvent again with the same parameters but instead of the subroutine name issue an empty string.  E.g.:

 

//enable 

OnEvent>KEY_DOWN,VK32,0,KeyPress 

 

... 

... 

 

//disable it 

OnEvent>KEY_DOWN,VK32,0, 

 

.. 

.. 

 

//enable it again 

OnEvent>KEY_DOWN,VK32,0,KeyPress