Onevent>Key_Down only fires once?
Moderators: Dorian (MJT support), JRL
Onevent>Key_Down only fires once?
I built a test script with a continuus loop monitoring the OnEvent>Key_Down. If fires and brings up my Dialog. I close the dialog and the loop continues, but the OnEvent won't work again unless I stop the script and restart.
Any ideas? Must be missing something here
Kind Regards,
Any ideas? Must be missing something here
Kind Regards,
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Sounds like you're stuck in the event subroutine. But as you haven't posted your code I can only guess. If you have not allowed the subroutine to end properly e.g. by jumping out of it with a goto, then, as far as OnEvent is concerned you're still in it, so it won't fire again - for this reason never jump out of event subroutines - always allow them to complete and get to the End statement.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Here is the code:
Label>Continue1
let>w=1
Label>trap
If>w=250
Goto>Continue1
Else
OnEvent>key_down,g,5,keys
let>w=w+1
message>%w%
Goto>trap
Srt>Displayit
//*********************************************************
//****** Get Startup times once on startup only ******
//*********************************************************
Dialog>Dialog3
Caption=Dialog3
Width=280
Height=226
Top=327
Left=643
Max=1
Min=1
Close=1
Resize=1
Edit=Hours,16,57,121,01
Edit=Minutes,17,87,121,30
Edit=Seconds,18,114,121,00
Button=DONE,155,59,75,25,1
Button=EXIT,157,108,75,25,2
EndDialog>Dialog3
WAIT>0.5
Label>MainLoop
Show>dialog3,result
If>result=1,Done
endif
If>result=3,DisplayMessage
endif
If>result=2,quit
endif
Goto>MainLoop
SRT>Done
Let>Preset_Time={(%Dialog3.Hours%*10000)+(%Dialog3.Minutes%*100)+%Dialog3.Seconds%*1}
//Message>Preset Time = %Preset_Time%
Goto>Continue1
END>Done
SRT>quit
exit
END>quit
END>Displayit
Label>Continue1
let>w=1
Label>trap
If>w=250
Goto>Continue1
Else
OnEvent>key_down,g,5,keys
let>w=w+1
message>%w%
Goto>trap
Srt>Displayit
//*********************************************************
//****** Get Startup times once on startup only ******
//*********************************************************
Dialog>Dialog3
Caption=Dialog3
Width=280
Height=226
Top=327
Left=643
Max=1
Min=1
Close=1
Resize=1
Edit=Hours,16,57,121,01
Edit=Minutes,17,87,121,30
Edit=Seconds,18,114,121,00
Button=DONE,155,59,75,25,1
Button=EXIT,157,108,75,25,2
EndDialog>Dialog3
WAIT>0.5
Label>MainLoop
Show>dialog3,result
If>result=1,Done
endif
If>result=3,DisplayMessage
endif
If>result=2,quit
endif
Goto>MainLoop
SRT>Done
Let>Preset_Time={(%Dialog3.Hours%*10000)+(%Dialog3.Minutes%*100)+%Dialog3.Seconds%*1}
//Message>Preset Time = %Preset_Time%
Goto>Continue1
END>Done
SRT>quit
exit
END>quit
END>Displayit
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
The "keys" subroutine does not exist. This OnEvent will never do anything.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Sorry, I was to quick to post the code. I was tinkering with it. Here is the correct code
Label>Continue1
let>w=1
Label>trap
If>w=250
Goto>Continue1
Else
OnEvent>key_down,g,5,Displayit
let>w=w+1
message>%w%
Goto>trap
Endif
Srt>Displayit
//*********************************************************
//****** Get Startup times once on startup only ******
//*********************************************************
Dialog>Dialog3
Caption=Dialog3
Width=280
Height=226
Top=327
Left=643
Max=1
Min=1
Close=1
Resize=1
Edit=Hours,16,57,121,01
Edit=Minutes,17,87,121,30
Edit=Seconds,18,114,121,00
Button=DONE,155,59,75,25,1
Button=EXIT,157,108,75,25,2
EndDialog>Dialog3
WAIT>0.5
Label>MainLoop
Show>dialog3,result
If>result=1,Done
endif
If>result=3,DisplayMessage
endif
If>result=2,quit
endif
Goto>MainLoop
SRT>Done
Let>Preset_Time={(%Dialog3.Hours%*10000)+(%Dialog3.Minutes%*100)+%Dialog3.Seconds%*1}
//Message>Preset Time = %Preset_Time%
Goto>Continue1
END>Done
SRT>quit
exit
END>quit
END>Displayit
Label>Continue1
let>w=1
Label>trap
If>w=250
Goto>Continue1
Else
OnEvent>key_down,g,5,Displayit
let>w=w+1
message>%w%
Goto>trap
Endif
Srt>Displayit
//*********************************************************
//****** Get Startup times once on startup only ******
//*********************************************************
Dialog>Dialog3
Caption=Dialog3
Width=280
Height=226
Top=327
Left=643
Max=1
Min=1
Close=1
Resize=1
Edit=Hours,16,57,121,01
Edit=Minutes,17,87,121,30
Edit=Seconds,18,114,121,00
Button=DONE,155,59,75,25,1
Button=EXIT,157,108,75,25,2
EndDialog>Dialog3
WAIT>0.5
Label>MainLoop
Show>dialog3,result
If>result=1,Done
endif
If>result=3,DisplayMessage
endif
If>result=2,quit
endif
Goto>MainLoop
SRT>Done
Let>Preset_Time={(%Dialog3.Hours%*10000)+(%Dialog3.Minutes%*100)+%Dialog3.Seconds%*1}
//Message>Preset Time = %Preset_Time%
Goto>Continue1
END>Done
SRT>quit
exit
END>quit
END>Displayit
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Your DisplayIt subroutine never ends. ever. So the OnEvent is still firing. It can't fire again.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Furthermore, if it was fixed so that it DOES end, the second time you fire your OnEvent you will get an error because you will be trying to create a dialog that already exists.
Remove the Goto>continue1 line.
Move the dialog blog to the top of your script so that it is only executed once.
Remove the Goto>continue1 line.
Move the dialog blog to the top of your script so that it is only executed once.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Thanks Marcus,
I found the problem thanks to your help. The loop within Display was not allowing the Displayit SR to end.
Now I got it.
I will display the code again for others to see:
Dialog>Dialog3
Caption=Dialog3
Width=280
Height=226
Top=327
Left=643
Max=1
Min=1
Close=1
Resize=1
Edit=Hours,16,57,121,01
Edit=Minutes,17,87,121,30
Edit=Seconds,18,114,121,00
Button=DONE,155,59,75,25,1
Button=EXIT,157,108,75,25,2
EndDialog>Dialog3
//**** MAIN LOOP ****
Label>Continue1
let>w=1
Label>trap
If>w=250
Goto>Continue1
Else
OnEvent>key_down,g,5,Displayit
let>w=w+1
message>%w%
Goto>trap
Endif
SRT>Displayit
//*********************************************************
//****** Get Startup times once on startup only ******
//*********************************************************
WAIT>0.5
//Label>MainLoop
Show>dialog3,result
If>result=1,Done
endif
If>result=3,DisplayMessage
endif
If>result=2,quit
endif
SRT>Done
Let>Preset_Time={(%Dialog3.Hours%*10000)+(%Dialog3.Minutes%*100)+%Dialog3.Seconds%*1}
END>Done
SRT>quit
exit
END>quit
END>Displayit
I found the problem thanks to your help. The loop within Display was not allowing the Displayit SR to end.
Now I got it.
I will display the code again for others to see:
Dialog>Dialog3
Caption=Dialog3
Width=280
Height=226
Top=327
Left=643
Max=1
Min=1
Close=1
Resize=1
Edit=Hours,16,57,121,01
Edit=Minutes,17,87,121,30
Edit=Seconds,18,114,121,00
Button=DONE,155,59,75,25,1
Button=EXIT,157,108,75,25,2
EndDialog>Dialog3
//**** MAIN LOOP ****
Label>Continue1
let>w=1
Label>trap
If>w=250
Goto>Continue1
Else
OnEvent>key_down,g,5,Displayit
let>w=w+1
message>%w%
Goto>trap
Endif
SRT>Displayit
//*********************************************************
//****** Get Startup times once on startup only ******
//*********************************************************
WAIT>0.5
//Label>MainLoop
Show>dialog3,result
If>result=1,Done
endif
If>result=3,DisplayMessage
endif
If>result=2,quit
endif
SRT>Done
Let>Preset_Time={(%Dialog3.Hours%*10000)+(%Dialog3.Minutes%*100)+%Dialog3.Seconds%*1}
END>Done
SRT>quit
exit
END>quit
END>Displayit
Hi MikeSr,
I don't understand why the OnEvent is in a goto loop.
Usually you just set it once at the beginning of the script.
Also, I see that the DisplayIt SRT does end at the bottom of the script. It has 2 other SRT's embedded in it. I guess that can be done but I'm not sure what it means. Usually each SRT is completely separate but one may call another.
Gale
I don't understand why the OnEvent is in a goto loop.
Usually you just set it once at the beginning of the script.
Also, I see that the DisplayIt SRT does end at the bottom of the script. It has 2 other SRT's embedded in it. I guess that can be done but I'm not sure what it means. Usually each SRT is completely separate but one may call another.
Gale
I agree with Gale. Though it does not specifically say in the Help File to do that, the example provided shows it that way. The Help File entry for On Event also begins by stating that it... "Establishes an event handler."gdyvig wrote:I don't understand why the OnEvent is in a goto loop.
Usually you just set it once at the beginning of the script.Gale
From forums posts I've seen, I've gathered that once established, that's it, you never have to run that line of code again. Also I have seen people ask if you can "un-establish" an event handler that has already been established and I believe the answer was no... no way to do that at the moment.
So if you know you definitely want a particular event handler established and active in your macro right from the start, just establish it at the top and never run that line again.
A common exception to that might be if you are making a macro where you want to use OnEvent to simulate a hotkey and you want to give a user a choice between several hotkeys they might choose, you would have to get their choice first before establishing the proper event handler. Again, I'd advise to only do it once. If the user wanted to change their choice, they should probably terminate the macro and fire it up again so they could choose differently... because again, currently you cannot "un-establish" an event handler that has already been established.
Only Marcus knows if putting an OnEvent> line inside a loop where it may get executed thousands or millions of times is actually going to hurt anything... it may not but its certainly not accomplishing anything either except eating up CPU cycles so best to just set it once at the top.
Take care
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 -
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 -
jpuziano
Gale
An easy solution is to have an if statement in the SRT the OnEvent runs. By controlling the value of a variable you can control whether the SRT acts or does nothing.Also I have seen people ask if you can "un-establish" an event handler that has already been established and I believe the answer was no... no way to do that at the moment.
Gale
Hi Gale,
Thanks... yes I think I've seen JRL do that in some of the stuff he's posted.
So while you can't un-establish an event handler once it has been established, you can stop that event handler from doing anything with a variable.
Of course, if you are trying to simulate a hotkey for a user running your macro (let's say they will be running it compiled)... and you would like to offer lots of choices of hotkey, say any letter of the alphabet plus a modifier key of either ALT, CTRL or SHIFT... well that's 78 separate OnEvent>KEY_DOWN lines you'd need... you'd get the user's choice and then run the correct one to setup the event handler... but then if the user changed their mind, you'd have to flip a variable that would prevent the established event handler from doing anything... and run the right line to setup the new desired event handler.
I suppose it could be done... but it sounds painful. If anyone has already tackled this or found a nifty way to offer a full range of user-selectable simulated hotkeys using OnEvent that works from within a compiled macro... please share the magic... or even your thoughts on how it might be done.
Thanks and take care
Thanks... yes I think I've seen JRL do that in some of the stuff he's posted.
So while you can't un-establish an event handler once it has been established, you can stop that event handler from doing anything with a variable.
Of course, if you are trying to simulate a hotkey for a user running your macro (let's say they will be running it compiled)... and you would like to offer lots of choices of hotkey, say any letter of the alphabet plus a modifier key of either ALT, CTRL or SHIFT... well that's 78 separate OnEvent>KEY_DOWN lines you'd need... you'd get the user's choice and then run the correct one to setup the event handler... but then if the user changed their mind, you'd have to flip a variable that would prevent the established event handler from doing anything... and run the right line to setup the new desired event handler.
I suppose it could be done... but it sounds painful. If anyone has already tackled this or found a nifty way to offer a full range of user-selectable simulated hotkeys using OnEvent that works from within a compiled macro... please share the magic... or even your thoughts on how it might be done.
Thanks and take care
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 -
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 -