Change states based on how long a button is held down

Mar 08, 2019

I'm assuming this isn't possible, but wanted to run it by everyone to find out for sure.  Here is what I would like to do:

I work for a agriculture equipment manufacturer and I would like to be able to simulate raising or lowering a header on a combine.  I know I could probably have 15 different states showing the header in different positions from all the way down to all the way up and then change these based on pressing the up or down control multiple times; however, in the real world you wouldn't press the button 15 times to raise or lower, you'd hold the button in until the desired position is achieved and then release it.  Is there any way to simulate this?  It might seem like it's not worth the effort; however, I want to teach a calibration procedure and it really won't feel real / simulate the real thing well unless I can achieve this.

Hopefully this makes sense; basically I want to have several states (images of the piece of equipment in different positions) and pick the state based on how long the raise / lower button is held.  Could I increment / decrement a counter based on how long a button is held and then use that to select the state?  or time how long the button is held down? or???

5 Replies
Ned Whiteley

Hi Mike,

There is always a solution to be found somewhere !

This is actually quite a simple one to solve. What I have done in the attached example is to make use of the fact that computer keyboards have a repeat rate built into them that repeats the keystroke as long as you keep your finger on the button.

In this case I have used the Down Arrow to "lower" the harvester header and the Up Arrow to "raise" the harvester header. I have set a variable called HeaderPosition that starts at zero (representing the stowed position) and then increases by 1 each time the Down Arrow key is pressed or each time the keystroke repeats due to the Down Arrow being held down. If you use the Up Arrow, the variable is decreased by 1 each time.

I have simply used this figure to represent the number of centimetres that the header is dropped or raised and set limits at 100 cm for fully down and 0 cm for stowed. You can, of course use the variable result in any way you need to.

Hope this helps

Ned Whiteley

Hi Tim and Mike,

One thing to note is that, if you are planning your projects solely for use on a desktop or laptop computer, either of the above two options would work. However, if you are also planning for your project to be accessible on mobile devices such as phones, then Michael's solution is your best bet as mine relies on a keyboard for input, due to its use of the built-in keystroke repeat function.

This discussion is closed. You can start a new discussion or contact Articulate Support.