Technical support and scripting issues
Moderators: Dorian (MJT support), JRL
-
wil
- Junior Coder
- Posts: 25
- Joined: Mon Dec 06, 2010 6:00 pm
Post
by wil » Sun May 11, 2014 9:14 pm
Hello,
Is it possible to reset or change the Keydown for an Onevent. I tried the following code, but that does not work
I was expecting here the KEY_DOWN should change from "a" to "t"...
Code: Select all
//press a
let>event_char_test=a
let>teller=0
OnEvent>KEY_DOWN,%event_char_test%,0,testing
SRT>testing
let>teller=0
MessageModal>ok!!
//press t ...
let>event_char_test=t
END>testing
label>loop
if>teller=0
Message>Press %event_char_test%
endif
let>teller=teller+1
wait>0.01
goto>loop
thnx in advance and best regards, wil
-
hagchr
- Automation Wizard
- Posts: 331
- Joined: Mon Jul 05, 2010 7:53 am
- Location: Stockholm, Sweden
Post
by hagchr » Mon May 12, 2014 3:07 pm
Hi, not sure if there is an easier way, but it seems to work if you add a flag and some lines to the main loop where you reset the old OnEvent and set up the new one:
//press a
let>event_char_test=a
let>teller=0
let>testflag=false
OnEvent>KEY_DOWN,%event_char_test%,0,testing
SRT>testing
let>teller=0
MessageModal>ok!!
let>testflag=true
END>testing
label>loop
if>testflag=true
//Disable old OnEvent by leaving out Subroutine
OnEvent>KEY_DOWN,%event_char_test%,0,
//press t ...
let>event_char_test=t
//Reset it with new event
OnEvent>KEY_DOWN,%event_char_test%,0,testing
let>testflag=false
endif
if>teller=0
Message>Press %event_char_test%
endif
let>teller=teller+1
wait>0.01
goto>loop View Snippet Page
-
JRL
- Automation Wizard
- Posts: 3526
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Mon May 12, 2014 3:30 pm
Here's a modification of the same method. According to Marcus' post
HERE, simply setting the event handler to a null subroutine will turn it off. So here is a sample of that with a subroutine built as a function for setting and resetting different OnEvent key presses. This eliminates the need for the flags.
If you run this the "a" key will be assigned for ten seconds then the "s" key will be assigned for ten seconds and the "a" key will no longer work.
Code: Select all
//Usage:
//Gosub>OnEventKey,Key or VK code,Modifier code,Sub routine name
//To work properly, the subroutine needs to be used for every eventkey assignment.
SRT>OnEventKey
If>LastKey={"LastKey"}
Else
OnEvent>key_down,LastKey,LastModifier,
EndIf
OnEvent>key_down,OnEventKey_var_1,OnEventKey_var_2,OnEventKey_var_3
Let>LastKey=OnEventKey_var_1
Let>LastModifier=OnEventKey_var_2
END>OnEventKey
Gosub>OnEventKey,a,0,Report
Wait>10
Gosub>OnEventKey,s,0,Report
Wait>10
SRT>Report
MDL>Current key = %OnEventKey_var_1%
END>Report
-
wil
- Junior Coder
- Posts: 25
- Joined: Mon Dec 06, 2010 6:00 pm
Post
by wil » Mon May 12, 2014 5:56 pm
Thnx hagchr and JRL.
Sorry, for some reason i didn't find Marcus' post before submitting this question.
Best regards, wil