How to use key commands to trigger a specific button in MATLAB App Designer

I've created a GUI for a research study where I want participants to listen to multiple different audio files. The way the GUI works is that when I press the "Play" button it plays the audio file. Then there are a bunch of questions with radio buttons to get responses from the participants. At the end there is a button "Save" to save those responses in csv file.
So far I've been using the mouse to click the individual buttons, but I was wondering if there is a way to trigger the Play Button using a simple key command like Spacebar. I tried using the key press fnc, but it only works when the Play button is pressed once using the mouse (after bringing the play button in focus). Is there a way to ensure that a specific button is already in focus when the app is launched so that I can use a key command to trigger it?

 採用された回答

Voss
Voss 2025 年 2 月 28 日

1 投票

"Is there a way to ensure that a specific button is already in focus when the app is launched"
Yes, in the app's startupFcn, call focus() on the button.

3 件のコメント

Shaunak
Shaunak 2025 年 3 月 1 日
編集済み: Shaunak 2025 年 3 月 1 日
Thank you so much! I'm surprised this wasn't mentioned on previous forum entries that asked the similar question.
Voss
Voss 2025 年 3 月 1 日

You're welcome! Any other questions, please let me know. Otherwise please Accept this answer. Thanks!

Stephen23
Stephen23 2025 年 3 月 1 日
"I'm surprised this wasn't mentioned on previous forum entries that asked the similar question. "
FOCUS was only introduced in R2022a: earlier threads are unlikely to mention this function.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

質問済み:

2025 年 2 月 28 日

コメント済み:

2025 年 3 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by