Detecting button auto-repeat?

Is there a way to tell if buttonClicked() was called due to the auto-repeat feature of the button?

I have a couple of buttons that move selected items up or down in a graph, and if they hold those buttons down, I continue moving the items up or down.

But these button presses add an entry to an Undo stack, and each time buttonClicked() is called from this auto-repeat feature, the new state of the graph is pushed onto an Undo stack. That’s not what a user would want. They’d want to only see this action add only 1 item to the Undo stack.

To accomplish that, what I want to do is to swap the results with the top stack item - as opposed to pushing it onto the stack - whenever the buttonClicked() comes from an auto-repeat. This would accomplish what the user wants.

So… is it possible to know whether buttonClicked() came from an auto-repeat, as opposed to the initial click on the button? Or do I need to make my own derived Button class that records this information and then makes it retrievable in buttonClicked()?

You could look into mouse events and raise a flag on the mouse down and mouse up events, then handle the undo manager stuff yourself in the buttons state change callback. First entry after mouse down gets added to a new position, successive entries while mouse is down replace the top of the stack. That’s what I’d be looking at, anyway.

Thanks. Yeah, I ended up deriving my own Button class that overrides mouseDown() and mouseUp(), and set/reset an atomic flag that says that the last event was a mouse down. Then, in buttonClicked() in my component, I use exchange(false) on that flag to check if it was just set to true (and immediately set it to false when checked). This way, I can tell if the buttonClicked() was the first such event after the mouse down, or a repeat event.