View Full Version : Add extra input if button is held down...
shezmu
29th July 2009, 11:04 PM
Hello.
Having a spot of trouble, being a CMS newbie (just bought an MFP).
What I would like to do is to have a button send a char, but if I hold the button down for a longer period, it should send a mousebutton 4 click as well.
This is what I have so far:
%DEFINE RunDelay 10
%DEFINE MbDelay 5
// CMS Script File
//
// Game Title:
// Written By:
// Date:
//
script
TIMER(ONDELAY,D1, RunDelay) = JS1.B1; //If button is held long enough..
PULSE ( D2 ) = D1; //When the delay is achieved (first time only) set D2
IF(D2) THEN
SEQUENCE
CMS.B5=TRUE; //Send MB4
DELAY(5);
CMS.B5=FALSE; //Release MB4
ENDSEQUENCE;
ENDIF;
CMS.B1 = JS1.B1; //Always send movement char
endScript
It doesn't seem to work very well. :P
Please enlighten me if there is some smooth way to do what I want :)
Bob Church
30th July 2009, 04:54 AM
Hi shezmu,
>> Having a spot of trouble, being a CMS newbie (just bought an MFP). <<
Actually, I'm kind of surprised mouse button 4 responds, they must have added support for it recently. I guess the CM would send it, I've never known Windows to recognize it natively, but if you can make MB4 work the rest should be relatively simple to fix up.
>> What I would like to do is to have a button send a char... <<
For the initial character, you can program it directly to the button up in the GUI. I don't know what the character is, I'll call it MB4. Set it to "Programmed Mode" (uncheck the "DX Mode" box on the right side of the screen) so it sends characters, then program the character directly to the button. If you just program it like:
MB4
it will be held down as long as the button is down and Windows will probably want to generate the autorepeats for it. You can force it to send just one pulse by programming:
MB4 NULL
It sees the NULL as a second character and that stops the character from being held down. You should just see it once.
>> ....but if I hold the button down for a longer period, it should send a mousebutton 4 click as well. <<
It's probably because of the IF block around the SEQUENCE. The script is single-threaded so it can't really stop in the sequence or it will stall the machine. When it hits the delay, it jumps out of the sequence so it can continue processing. When the delay has run out, it picks back up until something else comes along that requires it to stop. It's kind of a simple multi-tasking setup really. The problem is that if the IF comes up FALSE, the whole sequence block is skipped. The first time it hits the delay statement, it will jump out. The IF will be FALSE until you refire D2 the way you've got it running, then it will try to continue but even then it has to make several passes to get through 5 ticks and that's likely where you're getting the erratic response. It can only count on a clock tick when the IF comes up TRUE and it has to count to 5. It could take a long time and will certainly not be even.
You don't really need the IF though. You need to use a WAIT. The WAIT, has to see the button be FALSE and go to TRUE before it will pass control into the sequence. Once it does, it won't do it again until the sequence is complete and you've released the button for at least one time period. That's set on the "Programming Settings" tab, it defaults to 50 milliseconds but can be adjusted from 25 to 200 milliseconds. Lower values give a faster rate, 25 is about as fast as Windows will process them and they usually need to be down for one full frame time to be sure the sim sees them. I'm not sure how MB4 would respond though. If Windows is seeing it as a real mouse button it would likely treat it somewhat differently. Anyway, I'd leave it at 50 for starters, then fiddle with the value once it's basically running to see what improvement you might make there.
That same tick controls both the character rate and the ticks that the timers and things that the script sees. A "Delay( 1 )" is one tick of that clock, for example.
You're timer is basically setup right, the ONDELAY is the thing to use. You don't need to send it through the PULSE thing, though. The sequence won't restart until the WAIT sees it go the FALSE->TRUE transition and it's not already sequencing so it won't retrigger anyway.
That being the case, it should look more like this I'd think:
script
%DEFINE RunDelay 10
// Set up the delay timer
//
timer( ONDELAY, d1, RunDelay ) = js1.b1;
// Now set up the timed sequence
//
sequence
// Wait for the on delay to make the FALSE->TRUE transition.
// It will require that the sequence completes and that another
// transition is seen after that before it will pass into the
// sequence again.
//
wait( d1 );
// If we're here, d1 made the transition and we're in.
//
cms.b5 = TRUE;
// Wait for the click to propogate out of the script. The 5
// will be about 0.25 seconds.
//
delay( 5 );
// Now release cms.b5 and it's done.
//
cms.b5 = FALSE;
endSequence
// CMS.B1 doesn't need to send the character here anymore
// since it's up in the GUI now and controlled directly by
// the button.
endScript
Give that a try and see if it works any better for you. Let me know what you find out!
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
shezmu
30th July 2009, 06:24 AM
Hello Bob.
Actually I have no idea if Mousebutton 4 will work or not. It's just that I have hooked the CMS.b5 to be directx, mouse, and button 4...
If not I can always remap the command in-game to another button, and
I'm sure it will work awesome, I'll try it right way.
Thanks for your help.
Bob Church
30th July 2009, 08:09 AM
Hi shezmu.
>> Actually I have no idea if Mousebutton 4 will work or not. It's just that I have hooked the CMS.b5 to be directx, mouse, and button 4... <<
If it worked there, it should work fine. It doesn't really matter how you get cms.b5 to "click", the result will be the same.
>> If not I can always remap the command in-game to another button, and
I'm sure it will work awesome, I'll try it right way.
Thanks for your help.<<
Thank you for the information! The MB4 thing is helpful, I can avoid breaking it if I know it's there.
Let me know it goes!
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
shezmu
30th July 2009, 10:24 AM
FYI: Mousebutton 4 does NOT seem to work.
I was playing around and I thought something was wrong with the script, but
it is as you say that it does not work. I remapped the function that mousebutton 4 controls in the game instead as a workaround.
Bob Church
30th July 2009, 12:27 PM
Hi shezmu,
Okay, it's good to get it verified anyway. I looked into it a few years back and it seemed that mice with more than 3 were mainly dependent on the mouse manufacturers software. Windows native support looked to be just left, right, and middle buttons (1, 2, 3).
Thanks for letting me know!
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
Powered by vBulletin® Version 4.1.4 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.