App Designer push button callback on push/hold (not native ButtonPushFcn)

22 ビュー (過去 30 日間)
Rick Policy
Rick Policy 2021 年 10 月 18 日
コメント済み: Rick Policy 2021 年 10 月 22 日
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?

回答 (1 件)

Pavan Guntha
Pavan Guntha 2021 年 10 月 22 日
Hello Rick,
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!
  1 件のコメント
Rick Policy
Rick Policy 2021 年 10 月 22 日
Thank you for the suggestion Pavan.
However, the statebutton wasn't working for me either. The callback is still not executed until you click and release the button.
My application really needs a mechanism that can detect when the mouse button is pressed and held on the control (button) and also detect when the mouse button is released. If there was a way to querie the value of the mouse click states when it is positioned over top of a button then that would work too.





Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by