MATLAB: Button is being long pressed or just clicked

button longpressed

I have a GUI with a button and I want that if the button is clicked: something happens. If it's long pressed: after I release the button another thing happens. I'm not sure if there's a way to do exactly this but something similar would be nice. The important thing is that I maintain only one button.

Best Answer

Renato - I don't think that you can do this without customizing your GUI. There doesn't appear to be any event handling for mouse down and mouse up on the button itself. I was able to do something like you requested (see attached) but it required adding a callbacks to the button (ButtonDownFcn) and to the figure (WindowButtonDownFcn and WindowButtonUpFcn)....and the push button had to have its Enable property set to Inactive. The code handles the highlighting of the button and calling the pushbutton callback (once the button up event fires).
The attached code measures the time difference between the down and up events so you could use that value to determine if the button is clicked or long-pressed. (Tested on R2014a.)