MATLAB Answers

Is it possible to assign keyboard shortcuts to trigger certain parts of my app in app designer, and if so, how?

41 views (last 30 days)
rtbme17
rtbme17 on 30 Mar 2020
Answered: rtbme17 on 7 Apr 2020
I was wondering if it's possible to assign user defined keyboard shortcuts to parts of the app in app designer.
For example,using a menu item with ctrl+L, or simply just L. Not sure if this is possible, but if anyone knows, please share
Thanks!

Accepted Answer

rtbme17
rtbme17 on 7 Apr 2020
I found out what to do based on Mohammad Sami's reply to my question.
(1) Go to callbacks in the app designer window for the entire UIFigure in deisgn view
(2) In the 'keyboard' menu, go to KeyPressFcn and select <add KeyPressFcn callback> (should be at the top of the list). This will create a callback in code view for you to edit.
(3) In the callback, there will be a preset variable called 'key'. Set up a swtich/case for which key's you'd like to perform specific functions. 'key' will always providing the physical key pressed as a string in lowercase letters.
% Key press function: UIFigure
function UIFigureKeyPress(app, event)
key = event.Key;
switch key
case 'p'
app.PlotMyData(app);
app.Message.Value = key; % return key value
case 'f1'
app.ChangeData(app);
app.Message.Value = key;
case 'shift'
app.ChangeColor(app);
app.Message.Value = key;
case '1'
app.Message.Value = 'Pressed 1';
end
end
(4) As a side note for those who may not know, you can get a look at what the value of 'key' will be by creating a text box, and setting the value to key (shown above). This will help you designate keys for functions you may have.
Hope this helps someone else as well.

  0 Comments

Sign in to comment.

More Answers (1)

Abhisek Pradhan
Abhisek Pradhan on 2 Apr 2020
There is similar question in following link on configuring a GUI button to keypress. Hope it helps.https://in.mathworks.com/matlabcentral/answers/12034-gui-button-with-keyboard-shortcut

  1 Comment

rtbme17
rtbme17 on 6 Apr 2020
Hi Abhisek Pradhan,
Thanks for your response!
It seems like the solution provided implements 'uicontrol', which according to the MATLAB help database, is only suited for GUIDE. I am working with app designer, so I don't think it'll work for me.

Sign in to comment.


Translated by