A strange thing came up when I was working with the OnEvent and KEY_PRESS. See example script below.
If I put in eg. "END>keyx" at the end then it works fine every time. If I put in "END>key" (what I would have expected) then it triggers once and then hangs after I press key 2 or 3.
Not sure if a bug, or "key" somehow is reserved or if I am incorrectly passing parameters to the subroutine triggered to run.
View Snippet Page
Issue with OnEvent - KEY_PRESS
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
This syntax is wrong:
OnEvent>KEY_DOWN,k2,0,key,k2
This would be looking for a subroutine called "key,k2".
OnEvent wants only 4 parms.
OnEvent>KEY_DOWN,k2,0,key,k2
This would be looking for a subroutine called "key,k2".
OnEvent wants only 4 parms.
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,
Seems like this has been discussed before but I couldn't find it. I was thinking that you said something to the effect that though OnEvent can under certain conditions pass parameters like would be done in a GoSub> function, that it was unsupported and for some reason couldn't be made to work reliably. Could you clarify this because the following works just fine for me. If I run this script then press the Exc key the fifth parameter is clearly passed to the subroutine.
@hagchr
Where in the world did you come up the idea of putting in "keyx" as the end to the "key" subroutine block???
Seems like this has been discussed before but I couldn't find it. I was thinking that you said something to the effect that though OnEvent can under certain conditions pass parameters like would be done in a GoSub> function, that it was unsupported and for some reason couldn't be made to work reliably. Could you clarify this because the following works just fine for me. If I run this script then press the Exc key the fifth parameter is clearly passed to the subroutine.
@hagchr
Where in the world did you come up the idea of putting in "keyx" as the end to the "key" subroutine block???
Code: Select all
OnEvent>key_down,VK27,0,GoThere,Hello World
Label>Loop
Wait>0.01
Goto>Loop
SRT>GoThere
MDL>%GoThere_var_1%
Exit>
END>GoThere
JRL, pure coincidence, first it didn't work/trigger. When I aborted the program I happened to press the x-key by mistake, which ended up at the end of the code line. Then the program worked. So it is still odd to me that with parameters and the wrong code at the end it works ok (it triggers when I press each of the keys and sends the right message).
It would be great if there was a way to pass parameters to OnEvent since I want to track several keys and have kind of generic treatment the results.
It would be great if there was a way to pass parameters to OnEvent since I want to track several keys and have kind of generic treatment the results.
After little experimenting I see that the same result occurs if you leave off the subroutine END> completely. I think the only advantage to putting in "keyx" is that it prevents the editor from autocompleting the subroutine block if enter is pressed further into the script. But I also think that the "keyx" leaves the block open so it doesn't finish properly when evaluated by the script processor.
For example run the following. It is your script with keyx as the end of block and another MessageModal> line afterward which should never be seen but is called every time a "2" or a "3" is pressed.
For example run the following. It is your script with keyx as the end of block and another MessageModal> line afterward which should never be seen but is called every time a "2" or a "3" is pressed.
Code: Select all
//Initialize parameters (VK49=1, VK50=2, VK51=3)
CodeBlock
Let>k1=VK49
Let>k2=VK50
Let>k3=VK51
EndCodeBlock
//Events
CodeBlock
OnEvent>KEY_DOWN,k1,0,key_1
OnEvent>KEY_DOWN,k2,0,key,k2
OnEvent>KEY_DOWN,k3,0,key,k3
EndCodeBlock
Label>Main
Wait>0.2
Goto>Main
SRT>key_1
MessageModal>%k1% was pressed
END>key_1
SRT>key
If>key_var_1=%k2%
MessageModal>%k2% was pressed
Endif
If>key_var_1=%k3%
MessageModal>%k3% was pressed
Endif
END>keyx
MDL>more