how to implement "option+command+h" in App Designer?

4 ビュー (過去 30 日間)
Harald von der Osten
Harald von der Osten 2025 年 3 月 26 日
I would like to hide all other windows on the desktop (Mac) in App Designer when starting the programme. How do I programme the command sequence ‘option+command+h’? Thank you very much.

採用された回答

NVSL
NVSL 2025 年 3 月 28 日
I understand that you want to program the keyboard shortcut “option+command+h” before running your app so that all other windows in your mac desktop gets hidden.
As mentioned above, you can use Java robot in StartupFcn callback to simulate key presses as follows.
function startupFcn(app)
import java.awt.Robot;
import java.awt.event.KeyEvent;
robot = Robot();
VK_META = KeyEvent.VK_META;
VK_ALT = KeyEvent.VK_ALT;
VK_H = KeyEvent.VK_H;
robot.keyPress(VK_META);
robot.keyPress(VK_ALT);
robot.keyPress(VK_H);
robot.keyRelease(VK_H);
robot.keyRelease(VK_ALT);
robot.keyRelease(VK_META);
end
VK_META invokes “Command” key whereas VK_ALT invokes “Option” key in mac.
Hope this helps!
  1 件のコメント
Harald von der Osten
Harald von der Osten 2025 年 3 月 28 日
Hi @NVSL, thank you very much for your valuable help. I will continue to work with it

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

その他の回答 (1 件)

Oliver Jaehrig
Oliver Jaehrig 2025 年 3 月 27 日
I believe you need to find some code which is equivalent to Command + H which can be called in a system call from MATLAB. Then you can input this into the StartupFcn callback of your app.
Maybe other helpful discussion:
You could also try to use a Java robot to simulate key presses.
  1 件のコメント
Harald von der Osten
Harald von der Osten 2025 年 3 月 28 日
Hi @Oliver Jaehrig, thanks a lot for your help and for the link

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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by