Page 1 of 1
Help with bind and event
Posted: Mon Aug 16, 2004 10:13 am
by dedw8
I'm thinking this is a very simple thing to do yet in searching through all the posts and reading the manual I can't seem to figure it out. I'm writing my first macro and trying to do the following:
After I start my macro I want it to detect every time I press a key, say the 'e' key. I'm thinking I need to use events but not quite sure.
Any help is truly appreciated, and sorry if this is a dumb question.
Thanks,
D
Posted: Mon Aug 16, 2004 11:36 am
by fearless
This type of thing has usually been done with the varset command.
IE you would have an if statement with if varset = 0 then do this, if varset = 1 then do that.
Then you do an /echo varset 0 or /echo varset 1 to change the behavior.
The next step would be to use either a hotkey with the two echo's in it, or you could use a keybind.
Sorry for lack of better examples, but it should give you something to start searching for.
Re: Help with bind and event
Posted: Mon Aug 16, 2004 11:41 am
by Fuergrissa
dedw8 wrote:I'm thinking this is a very simple thing to do yet in searching through all the posts and reading the manual I can't seem to figure it out. I'm writing my first macro and trying to do the following:
After I start my macro I want it to detect every time I press a key, say the 'e' key. I'm thinking I need to use events but not quite sure.
Any help is truly appreciated, and sorry if this is a dumb question.
Thanks,
D
Could you give me an example of Why you would want to do it, maybe there is a better way to accomplish your goal.
Posted: Mon Aug 16, 2004 12:45 pm
by Cr4zyb4rd
Several ways to do this. If there's a behavior in your script that you want to trigger or toggle, you can do this.
Code: Select all
/custombind add ToggleEKey
/custombind set ToggleEKey /varset EKey ${If[${EKey},0,1]}
/bind ToggleEKey e
be sure to
in your macro or config files. If there's some behavior you want to continue WHILE you have the key held down, and then stop as you release it, use
Code: Select all
]/custombind add ToggleEKey
/custombind set ToggleEKey /varset EKey 1
/custombind set ToggleEKey-up /varset EKey 0
/bind ToggleEKey e
instead.
You could also do something like
Code: Select all
/custombind set EKeyStuff /echo Please do the EKey stuff now.
and then in your macro
Code: Select all
#event EKeyHit [MQ2] Please do the EKey stuff now.
Sub Event_EKeyHit
blah blah blah
/return
to make an event, but this will spam your MQ window whenever you hit a key. Something like this could also be done using timers.
Either method will also work if you want to queue up multiple events, like "nuke 4 times if I spam the key 4 times", just use some '/varcalc EKey +1' action in there somewhere, and reduce the counter each time you handle the event.
Posted: Mon Aug 16, 2004 1:46 pm
by dedw8
You guys are great. Someone asked for an example of what I'm trying to do, here goes:
1. Start my macro and wait for 'e' to be pressed
2. Every time 'e' is pressed do a certain action (I have an array of actions, so each 'e' press goes to the next, at the end of the array it goes back to the beginning)
3. I will manually terminate my macro.
I've got everything done save for the capture of the 'e' key, but wasn't sure if I would need a doevent loop and use bind or not.
I think Cr4zyb4rd is on the right track for what I need but its not a toggle, more capturing a keystroke to fire some code.
This confused me a little as well as i'm not quite sure whats happening after the varset:
Code: Select all
/custombind set ToggleEKey /varset EKey ${If[${EKey},0,1]}
Thanks again,
D
Posted: Mon Aug 16, 2004 3:13 pm
by Cr4zyb4rd
If the value of ${EKey} is other than 0, set it to 0. Otherwise set it to 1. (ie toggle the value between true/false)
Posted: Wed Aug 18, 2004 3:58 pm
by JP5
If you have an array, wouldn't you want to have values from 0 to ${ArrayName.Size} ?
If that's the case, here is what I would do.
Code: Select all
/declare ET[n] int local 0
/custombind add EToggle
/custombind set EToggle /docommand ${If[${ET}==${ET.Size},/varset ET 1,/varcalc ET ${ET+1}]}
/bind EToggle E
If ET array is at max, it sets it back to 1 (i'm not sure if you wanted it set to 1 or 0, so change that if it isn't right)