How to start an event with onmousedown stop with onmouseup

My client has a project which includes a number which is increased by one when you click one button, and decreased by one when you click another button. Easy stuff.

They want to be able to hold down on the ‘increase button’ (I’m thinking onmousedown…) and have the number increase by 10, wait one second, then increase by 10 again until they release. (I’m thinking onmouseup.)

I’ve tried a couple of different things, mostly like

“onmousedown (if value of ‘mouse’ is not 0)
increase the value by 10,
set the text to the value,
move the number rectangle by 0,0”

“onmove on the number rectangle
wait 1000ms,
fire onmousedown”

set value of ‘mouse’ to 1,
set value of ‘mouse’ to 0 (set it immediately back to 1 so it will work again if need be)

This should be such a simple thing, but I can’t get it to work at all. Any ideas?

Have a look at the attached. Your logic looks like it should work, but the attached is how I would do it.

MouseDown Incrementer.rp (56.6 KB)

1 Like

That works like a champ! The only problem is, I need to be able to increment by 1 when the button is clicked (onclick) and by 10 every second as long as it remains pressed (onmousedown).

I’m not sure how or if an onmousedown/onmouseup can be used with an onclick on the same widget. Does onmousedown + onmouseup = onclick always?

I believe the down and up events fire first independently before the click fires. But each do fire independently.

In your scenario… should it first increment by 1 and then by 10 if it’s held, or should it wait to see if the user has held the button before increment and if held increment by 10 instead of 1.

The second scenario is what I’m going for. If they click quickly, increment by 1. If they hold it down, don’t increment by 1, but instead increment by 10.

There may be a more elegant way to handle this - but see attached. If you think of a way to simplify, would like to see it :slight_smile:

MouseDown and Click Incrementer.rp (56.3 KB)

Same premise as before, but added in a timer of sorts to treat a hold of 1 second or more different than a click.

This works like a charm. Stupid question now… What if I wanted to have a second button to decrement the same value? In looking over your file, I don’t see an easy way to modify that.

I’m sure it’s super simple, but I’m just not seeing it.

Here’s how i’d do it. Add a label that is set to +1 or -1 based on the buttons. Then, on move, multiply the 1 or the 10 by the label so that when the decrement button is pushed it adds a negative instead:

The LVAR1 variable is set to the text on the new label widget

Sample file here:
MouseDown and Click Incrementer with decrement.rp (59.2 KB)