Script execution while button pressed

Hi I would like a script to execute repeatedly while a button is pressed down.
For example, increment a number by 1 while the button is pressed down, and stop incrementing when the button is no longer pressed/in focus.

I can only seem to be able to get the button to increment ONCE on mouse pressed event script.

Will i have to make a custom event method? None of the events in the standard component scripting window seem to be able to do the job.

Thanks

You could use a timer to accomplish this.

On your button create a custom property for example “pressed” of type Boolean.

In the button’s mouse pressed event set the value to True. Set it to False in the mouse released event.

Add a timer and bind it’s “Running” property to the buttons custom property (“pressed”).

In the timer’s action performed event add one to the current value of your number.

The timing of how fast thew value increments can be adjusted by changing the timer’s Delay property.