OnEvent help

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

OnEvent help

Post by Rain » Mon Jan 16, 2006 3:07 pm

I like the OnEvent feature but I'm having problems with it stepping out the subroutine.
What I want to is have the script go to a loop when the alt and shift keys are pressed and wait for the client to press a button in the dialog to continue with the task.

Quick example

Label>Main_Loop
Wait>.05
OnEvent>KEY_DOWN,VK32,3,KeyPress
Goto>Main_Loop
SRT>KeyPress
///Here is where I want to step out of the subroutine and go to another loop
Label>Second_Loop
Wait>.05
///wait for dialog button pressed then go back to Main_Loop
GetDialogAction>Dialog1,result
If>result=1,Main_Loop
goto>Second_Loop

Is it possible to step out of a subroutine when using OnEvent and if so how?

Thanks for any help with this

Rain
Last edited by Rain on Mon Jan 16, 2006 3:10 pm, edited 1 time in total.

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

Post by Marcus Tettmar » Mon Jan 16, 2006 3:08 pm

Yes, you can jump out of a subroutine to any point. Just use a Goto statement to jump to a label outside of the subroutine.
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
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jan 16, 2006 3:35 pm

What am I doing wrong?
Here is a test script I'm using that's stepping out of the subroutine and back to loop1 but when back in loop 1 it's not recognizing when the p key is pressed.

//VK80=p
label>main
mdl>loop1 press P
label>loop1
wait>.05
OnEvent>KEY_DOWN,VK80,0,pause
goto>loop1
srt>pause
let>count=0
goto>loop2
label>loop2
mdl>loop2 Click OK
add>count,1
if>count=5,main
goto>loop2

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

Post by Marcus Tettmar » Mon Jan 16, 2006 3:46 pm

Hi,

Ah, you've got the wrong end of the stick when it comes to what OnEvent does. OnEvent is usually declared at the START of the script. When p is pressed it will run the subroutine regardless of where the script is.

I'm not quite sure from your script what you are trying to do because you have OnEvent unnecessarily redeclared in each loop. Don't forget that subroutines always return back to the point they were called. So you don't need to jump anywhere at the end.

Try this example. Here we have a simple loop which just waits 0.5 seconds and increments a counter. At the start of the script we have an OnEvent handler which says whenever "p" is pressed run the DoPKey subroutine. The loop will run forever, but if p is pressed a message box will pop up saying "p was pressed" and the loop will continue. Note that my message box also displays the value of the loop counter, which helps to demonstrate that the loop continues without you having to do anything. You don't need to do anything to make the subroutine return to the point in the script where it was called:

OnEvent>KEY_DOWN,p,0,DoPKey

Let>k=0
Label>loop1
wait>.05
Let>k=k+1
Goto>loop1

SRT>DoPKey
//p key was pressed
MessageModal>p was pressed, k=%k%
End>DoPKey
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
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jan 16, 2006 3:50 pm

Thanks this is exactly what I was trying to accomplish, for some reason I thought OnEven> had to be in the loop. :oops:

Thank you for your help

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jan 16, 2006 4:15 pm

It is still not working the way I want it to. I want the script to pause by going to loop2 when the p key is pressed. I’ve added the c counter to mimic an action that would normally occur when a button is pressed in the dialog telling the script to go back to loop1 which is the main loop. The script goes back to loop1 perfectly but when I press the P key again it is not going back to loop2. I don’t want to use a subroutine because I want the script to pause until the user is ready to continue by pressing the continue button in the dialog, in the example script the counter acts as the dialog button.
I hope this makes sense.


OnEvent>KEY_DOWN,p,0,DoPKey
Let>k=0
label>pre loop1
mdl>Starting loop1
Label>loop1
wait>.05
Let>k=k+1
Goto>loop1

SRT>DoPKey
//p key was pressed
MessageModal>p was pressed, k=%k%
let>c=5
goto>loop2
label>loop2
mdl>Returning to loop1 in %c%
let>c=c-1
if>cloop2

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

Post by Marcus Tettmar » Mon Jan 16, 2006 4:21 pm

I'm very confused!

If I understand you right you want the p key to pause the script. Once it is paused you want to wait until the p key is pressed again to resume the script. (Why not just press the Pause key - it already does that).

But as an example this script pauses the loop when p is pressed and then waits until the user presses the r key before continuing again:

OnEvent>KEY_DOWN,p,0,DoPKey

Let>k=0
Label>loop1
wait>.05
Let>k=k+1
Goto>loop1

SRT>DoPKey
//p key was pressed
MessageModal>Paused, press r to resume
//Now wait until r is pressed
WaitKeyDown>r
MessageModal>Resumed
End>DoPKey

Does that help?
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: 3502
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jan 16, 2006 4:34 pm

Rain,
One thing I've noticed with your posts is you are not posting an "END" to your subroutines.

SRT>XXXXX
//do something
END>XXXXX


Another thing: The OnEvent requires a subroutine, but the subroutine could have one goto statement that goes to a label. This would effectively make the OnEvent function jump to a label.

OnEvent>KEY_DOWN,p,0,DoPKey

SRT>DoPKey
goto>loop2
END>DoPKey


Hope this is helpful,
Dick

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jan 16, 2006 4:48 pm

I don't mean to confuse you. Sometimes it's hard to put what's in your head to words.
I only want the OneEvent P key to work in the main loop (loop1) but when the scripts goes to loop2 (which is the pause loop) I want to use the dialog button to resume the script and go back to the main loop (loop1) and when the P key gets pressed again I want it to go to loop2 (pause loop) again. In some scripts of mine the mouse is moving too fast to use the dialog button, that's the reason why I want to use the P key to pause it.

I have been using the libfunc> to do what I'm trying to accomplish with OnEvent
LibFunc>User32,GetKeyState,KEY_PRESSED,80
if>KEY_PRESSED=1,pause
Since OnEven is so much easier I would like to figure out how to use it the same way I would LibFunc.

Hi Dick
I’ve added end>DoPKey after goto>loop2 and it’s not making any difference at all, I’m still not able to pause the script a second time, it almost seems like the OnEvent command is gone after the script steps out the subroutine.

Thanks

Rain

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

Post by Marcus Tettmar » Mon Jan 16, 2006 4:51 pm

Ok, this pauses when you hit the p key. The script then does nothing until you hit the p key again.

OnEvent>KEY_DOWN,p,0,DoPause

Let>k=0
Label>loop1
wait>.05
Let>k=k+1
Goto>loop1

SRT>DoPause
MessageModal>_Paused
WaitKeyDown>p
MessageModal>_Resumed
End>DoPause
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
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jan 16, 2006 5:17 pm

I hate to be a pest.
I understand your script and it works perfectly but it is not doing me any good because when my script goes to the pause loop it is waiting for a dialog actions such as to continue the script, to go to my website, change the speed etc.

Here is a more detailed example script maybe it helps to understand what I’m trying to do here.


OnEvent>KEY_DOWN,p,0,DoPKey
Dialog>Dialog1
Caption=
Width=129
Height=114
Top=238
Left=446
Max=1
Min=1
Close=1
Resize=1
Label=Paused,8,0,true
Button=Start,8,16,105,25,1
Button=My Website,8,48,105,25,3
EndDialog>Dialog1

show>Dialog1
Label>pause
let>Dialog1.msLabel0=Paused
let>Dialog1.msButton1=Start
rda>Dialog1
label>pause loop
wait>.005
gda>Dialog1,r
if>r=1,pre main loop
if>r=2,2
if>r=3,website
goto>pause loop

label>pre main loop
let>Dialog1.msLabel0=Press P to Pause
let>Dialog1.msButton1=&
rda>Dialog1
label>main loop
wait>.005
gda>Dialog1,r
if>r=2,2
///Do something else example
gpc>123,123,color
if>color=123,take action
goto>main loop

label>take action
///Do something
goto>main loop

label>website
///load website
let>Dialog1.msLabel0=Loading website
let>Dialog1.msButton1=&
rda>Dialog1
wait>1
rda>Dialog1
goto>pause
SRT>DoPKey
let>Dialog1.msLabel0=P Key was pressed
let>Dialog1.msButton1=&
rda>Dialog1
wait>1
goto>pause
end>DoPKey
label>2


Thank you for your time and help

Rain
Last edited by Rain on Mon Jan 16, 2006 5:23 pm, edited 1 time in total.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jan 16, 2006 5:21 pm

I forgot to add that I want the script to go to the pause loop every time the user presses the P key while in the main loop not only one time like it’s doing now.

Thanks

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jan 16, 2006 5:34 pm

Here is the same script but this time I'm using the lib function and every time I press the P key it goes to the pause loop.


Dialog>Dialog1
Caption=
Width=129
Height=114
Top=238
Left=446
Max=1
Min=1
Close=1
Resize=1
Label=Paused,8,0,true
Button=Start,8,16,105,25,1
Button=My Website,8,48,105,25,3
EndDialog>Dialog1

show>Dialog1
Label>pause
LibFunc>User32,GetKeyState,KEY_PRESSED,80
if>KEY_PRESSED=1
sen>p
endif
let>Dialog1.msLabel0=Paused
let>Dialog1.msButton1=Start
rda>Dialog1
label>pause loop
wait>.005
gda>Dialog1,r
if>r=1,pre main loop
if>r=2,2
if>r=3,website
goto>pause loop

label>pre main loop
LibFunc>User32,GetKeyState,KEY_PRESSED,80
if>KEY_PRESSED=1
sen>p
endif
let>Dialog1.msLabel0=Press P to Pause
let>Dialog1.msButton1=&
rda>Dialog1
label>main loop
wait>.005
LibFunc>User32,GetKeyState,KEY_PRESSED,80
if>KEY_PRESSED=1,DoPKey
gda>Dialog1,r
if>r=2,2
if>r=3,website
///Do something else example
gpc>123,123,color
if>color=123,take action
goto>main loop

label>take action
///Do something
goto>main loop

label>website
///load website
let>Dialog1.msLabel0=Loading website
let>Dialog1.msButton1=&
rda>Dialog1
wait>1
rda>Dialog1
goto>pause
SRT>DoPKey
let>Dialog1.msLabel0=P Key was pressed
let>Dialog1.msButton1=&
rda>Dialog1
wait>1
goto>pause
end>DoPKey
label>2


I hope this explains it even more.

Thanks

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

Post by Marcus Tettmar » Mon Jan 16, 2006 5:43 pm

Try this:

OnEvent>KEY_DOWN,p,0,DoPKey
Let>gPaused=FALSE

Dialog>Dialog1
Caption=
Width=129
Height=114
Top=238
Left=446
Max=1
Min=1
Close=1
Resize=1
Label=Paused,8,0,true
Button=Start,8,16,105,25,1
Button=My Website,8,48,105,25,3
EndDialog>Dialog1

show>Dialog1
Label>ActionLoop
gda>Dialog1,r
if>r=1,DoPKey
if>r=2,2
if>r=3,websitepppppppp
If>gPaused=TRUE,doPause
goto>ActionLoop

SRT>website
///load website
let>Dialog1.msLabel0=Loading website
let>Dialog1.msButton1=&
rda>Dialog1
wait>1
rda>Dialog1
END>website

SRT>DoPKey
If>gPaused=TRUE
Let>gPaused=FALSE
Let>Dialog1.msLabel0=Paused
Let>Dialog1.msButton1=Start
Else
Let>gPaused=TRUE
Let>Dialog1.msLabel0=Resumed
Let>Dialog1.msButton1=Resume
Endif
rda>Dialog1
End>DoPKey

SRT>doPause
Wait>0.1
gda>Dialog1,r
If>r=1,DoPKey
If>gPaused=TRUE,doPause
END>doPause

label>2
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
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jan 16, 2006 10:33 pm

Thanks again for all your help and the example script, your last script is what I was looking for. :)

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