|
Trigger |
Top Previous Next |
|
Under the Trigger tab of the Macro Properties dialog you can specify a condition which should trigger the macro. Trigger types include
Window Event
File Event:
Folder Event
Custom Trigger
Macro Scheduler needs to be running for these triggers to be actioned.
More triggers can be implemented by building them into the script itself. Events and conditions can be coded into continuously looping macros so that they themselves detect conditions and act on them - e.g. screen changes, window changes, object caption changes, event log entries, ini file values, registry values, and almost anything you can think of.
Custom Triggers
Custom triggers allow you to define any kind of trigger imaginable by coding the trigger check yourself using MacroScript code. There are some rules:
A trigger script must have two subroutines as follows:
Trigger: This subroutine is executed periodically (less than once a second) by the scheduler and is used to determine whether or not the macro should fire. Set MACRO_RESULT to "TRUE" (upper case) to cause the trigger to fire (i.e. to run the macro). Setting MACRO_RESULT to anything else (or not setting it) will do nothing. So, the macro will not run until MACRO_RESULT is "TRUE" (upper case). The subroutine name is case sensitive.
Reset: Once Trigger returns "TRUE" the macro will run and thereupon the scheduler will no longer run the Trigger routine and instead will keep running Reset until it returns "TRUE" (upper case). Once Reset returns TRUE the scheduler will again run Trigger. Note, the subroutine name is case sensitive.
Since Trigger routines are run frequently on a very tight interval they should be kept as small as possible and should not be long running. Don't make Trigger scripts that perform too much complicated processing or include delays as this could cause resource issues.
Here's a small example trigger script which implements a simple Window Open trigger:
SRT>Trigger IfWindowOpen>Calculator Let>MACRO_RESULT=TRUE Else Let>MACRO_RESULT=FALSE Endif END>Trigger
SRT>Reset IfWindowOpen>Calculator Let>MACRO_RESULT=FALSE Else Let>MACRO_RESULT=TRUE Endif END>Reset
|