Multiple Event Triggers

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
rtapper
Newbie
Posts: 1
Joined: Tue Nov 17, 2009 12:35 am

Multiple Event Triggers

Post by rtapper » Wed May 01, 2013 4:26 am

Hi Marcus,

I have come across a problem where I have set up multiple event triggers using the OnEvent command.

When 1 event triggers, the expected routine is called.
If a 2nd (different) event occurs whilst the first event is still being processed, then the 2nd event is not being triggered until the original handler routine has completed.

Example code below is used to trigger HandleNotePad when Notepad is opened, which then starts Windows Explorer. A 2nd Event handler is set up to display a Message if Explorer opens.

Code: Select all

OnEvent>WINDOW_OPEN,Untitled - Notepad,1,HandleNotePad
OnEvent>WINDOW_OPEN,Computer,1,HandleExplorer

Repeat>True
    Wait>1
Until>True


SRT>HandleNotePad

    IF>_HandleNotePad=1,ExitHandleNotePad
    Let>_HandleNotePad=1
    ' Open Explorer
    PRess LWinKey
    Send>e
    Release LWinKey

'Repeat>True
'    Wait>1
'Until>True

    Label>ExitHandleNotePad
END>HandleNotePad

SRT>HandleExplorer

    IF>_HandleExplorer=1,ExitHandleExplorer
    Let>_HandleExplorer=1

    MDL>Here!
    Label>ExitHandleExplorer
END>HandleExplorer


With the Repeat...Until code commented out in the HandleNotePad routine, both events are able to trigger and the Here! message appears.
With the Repeat...Until code not commented out, Explorer is opened, but no Here! message appears.

Can you advise how to get around this problem as we have some scripts that are causing problems when multiple events happen almost simultaneously.
The only stupid question is an unasked question. If you don't know - ASK!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 01, 2013 9:31 am

There's only one thread for all events, so event handling has to be synchronous. One event will have to wait for the other.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 01, 2013 9:12 pm

There's only one thread for all events, so event handling has to be synchronous. One event will have to wait for the other.
... or you could create a second thread.

Code: Select all

OnEvent>WINDOW_OPEN,Untitled - Notepad,1,HandleNotePad

LabelToVar>HandleExplorerScript,vScriptData
IfFileExists>%Temp_dir%HandleExplorerScript.scp
  DeleteFile>%Temp_dir%HandleExplorerScript.scp
EndIf
WriteLn>%Temp_dir%HandleExplorerScript.scp,wres,vScriptData
ExecuteFile>%Temp_dir%HandleExplorerScript.scp

Repeat>True
    Wait>1
Until>True

SRT>HandleNotePad
    IF>_HandleNotePad=1,ExitHandleNotePad
    Let>_HandleNotePad=1
    ' Open Explorer
    PRess LWinKey
    Send>e
    Release LWinKey

Repeat>True
    Wait>1
Until>True

    Label>ExitHandleNotePad
END>HandleNotePad

/*
HandleExplorerScript:
OnEvent>WINDOW_OPEN,Computer*,1,HandleExplorer

Repeat>True
    Wait>1
Until>True=1

SRT>HandleExplorer

    IF>_HandleExplorer=1,ExitHandleExplorer
    Let>_HandleExplorer=1
    Let>True=1

    MDL>Here!
    Label>ExitHandleExplorer
END>HandleExplorer
*/

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts