Event trigger NOW, method sample

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

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

Event trigger NOW, method sample

Post by JRL » Thu Feb 11, 2010 6:36 am

Here's a quickly thrown together sample of how an event trigger might be captured for use at a later time. As mentioned in a recent postif there is a long wait, event triggers can't fire while the script is waiting. However, by writing the keypress event to a secondary script and having that script create a file that could be sensed by the master script's File_Exists event trigger. A keypress can be made by the user and later activated in the master script when the master script has finished waiting.

Code: Select all

GoSub>WriteKeyDownEventControlScript

OnEvent>File_Exists,%Temp_Dir%Capturefile~.tmp,0,VK112

SRT>VK112
  DeleteFile>%Temp_Dir%Capturefile~.tmp
  WriteLn>%Temp_Dir%Kill_VK112_Event~.tmp,wres,1
  DeleteFile>%scp_file%
  MDL>Alt + F11 was pressed%CRLF%Cleaning up and leaving.
  Exit>0
END>VK112

Label>Loop
  Wait>5
Goto>Loop


SRT>WriteKeyDownEventControlScript
  Let>scp_File=%temp_dir%temp_VK112_scp_file.scp

  WriteLn>%scp_file%,wres,OnEvent>Key_down,VK122,3,Capture
  WriteLn>%scp_file%,wres,Let>CaptureFlag=0
  WriteLn>%scp_file%,wres,SRT>Capture
  WriteLn>%scp_file%,wres,  If>CaptureFlag=0
  WriteLn>%scp_file%,wres,    WriteLn>%Temp_Dir%Capturefile~.tmp,wres,1
  WriteLn>%scp_file%,wres,    Message>Thank you for the key press... Please Wait.
  WriteLn>%scp_file%,wres,  EndIf
  WriteLn>%scp_file%,wres,  Let>CaptureFlag=1
  WriteLn>%scp_file%,wres,END>Capture

  WriteLn>%scp_file%,wres,Label>Loop
  WriteLn>%scp_file%,wres,  If>CaptureFlag>0
  WriteLn>%scp_file%,wres,    Add>CaptureFlag,1
  WriteLn>%scp_file%,wres,    If>CaptureFlag>10
  WriteLn>%scp_file%,wres,      Let>CaptureFlag=0
  WriteLn>%scp_file%,wres,    EndIf
  WriteLn>%scp_file%,wres,  EndIf
  WriteLn>%scp_file%,wres,  IfFileExists>%Temp_Dir%Kill_VK112_Event~.tmp
  WriteLn>%scp_file%,wres,    DeleteFile>%Temp_Dir%Kill_VK112_Event~.tmp
  WriteLn>%scp_file%,wres,    Exit>0
  WriteLn>%scp_file%,wres,  EndIf
  WriteLn>%scp_file%,wres,Goto>Loop

  ExecuteFile>%scp_file%
END>WriteKeyDownEventControlScript

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Feb 17, 2010 12:12 am

Hi JRL,

Just wanted to say thanks for taking the time to post this example.

This definately should ensure the keypress is not lost, could be stored and acted on later... and as written, provides immediate feedback to the user about the keypress... even though the main script may be unable to respond for quite a while.

Very clever and a great example... thanks for all your contributions on the forums! :)
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Post by JRL » Wed Feb 17, 2010 3:26 am

You're all welcome. I wish I had time to do more. There's only one way that I have to express my gratitude for this absolutely outstanding forum. That is to post those ideas that I have that seem like they could be useful.

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