フィルターのクリア

F Keys as accelerators, not allowed!

6 ビュー (過去 30 日間)
Antony
Antony 2024 年 2 月 8 日
コメント済み: Antony 2024 年 2 月 14 日
I'm using app designer, when I try to add the 'F5' key as an accelerator to a menu item,
app design gives me the message:
Its seems odd that function keys would not be allowed since they are amungst the most common short cuts.
What am I missing here.
Is there a way to make this work.

採用された回答

Ayush Singh
Ayush Singh 2024 年 2 月 14 日
Hi Antony
According to my comprehension, you are trying to add 'F5' key as an accelerator to a menu item but getting an error on doing so.
In MATLAB App Designer, when you try to set an accelerator key for a menu item, the accelerator property typically expects a single character (such as 'N' for a "New" command) or an empty character array.
This is why you are seeing the error message when you try to set 'F5' as the accelerator, as 'F5' is more than one character and is not recognized as a valid input for the property.
However, there is a way to work around this limitation by using the 'KeyPressFcn' callback of the figure (the main UI window) to detect when the F5 key is pressed.
As a workaround try out the following:
% Assuming 'app' is the handle to your application
app.UIFigure.KeyPressFcn = @app.figureKeyPress;
% Now define the callback function within your app
% Callback function that gets executed on key press in the figure
function figureKeyPress(app, event)
% Check if the pressed key is F5
if strcmp(event.Key, 'f5')
% Call the function or execute the code associated with the menu item
app.menuItemCallback();
end
end
% The callback function for your menu item
function menuItemCallback(app)
% Code that the menu item would execute
end
  1. We set the 'KeyPressFcn' property of the figure to a custom callback function that you will define.
  2. In the callback function, check if the pressed key is 'f5'.
  3. If 'f5' is detected, execute the same code you would have tied to the menu item's accelerator.
I hope the above workaround resolves your query.
  1 件のコメント
Antony
Antony 2024 年 2 月 14 日
Many thanks for your answer and code, this works perfectly.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by