App Designer push button callback on push/hold (not native ButtonPushFcn)
45 views (last 30 days)
Show older comments
Rick Policy on 18 Oct 2021
Answered: Josep Llobet on 22 Sep 2022
I have a need for a callback(s) that reacts to when:
1) Button is pushed
2) Button is released
The native ButtonPressFcn only is called when the button is pressed then released. I could not find anything in the community that would help with a callback, so I tried to instantiate a timer that polls the state of the button. However, the button does not have a "Value" property.
Is there another mechanism or callback that I can use to either poll the value of the button or a true button push/hold callback?
Pavan Guntha on 22 Oct 2021
You could leverage State Button instead of Push Button. When the Push Button is clicked once, the button appears to press and release. When the State Button is clicked, the button remains in the pressed or released state until it is clicked again. Use the “value” variable in the ButtonValueChanged callback of the State Button to know the state of the button an then take an action.
For more details you could have a look the documentation page of State Button.
Hope this helps!
Quang Vinh Nguyen on 27 Mar 2022
I have a same problem, still not solve it
Did you find any solutions?
Josep Llobet on 22 Sep 2022
If you want to execute the button, you must execute the 'execution' command of that one. As example, in a app.OriginalButton button:
Note that when you are writting in the App Designer the button name, it automatically suggest the 'button' statement, in this case OriginalButtonValueChanged, that you can use.
But, if you want to execute an State Button, surely you will need to re-define the state of it previously, it means that first you need to change the value (pushed or not) and then execute it. It is because when you click in State Button, you change the value with the click and then the callback of the button (OriginalButtonValueChanged) is executed. Here what I write in a problem of this style:
app.OriginalButton.Value = true;
app.OriginalButton.Value = false;
Hope this help!
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!