How to assign shortcuts to user interface control buttons?
Show older comments
A script I am using opens a user interface with several buttons. To make its use more efficient I want to access the control buttons (uicontrol) with a keypress instead of mouse click (both should be possible ideally). How to I do this if the function does a callback to another function (here: to 'newmaxmin')? Does this change anything?
xy = [0 0];
figmaxmin = figure('Units','pixels','KeyPressFcn', @keyPress, ...
'Color',[0.5 0.8 0.8], ...
'Name','Vérification des Max et Min', ...
'MenuBar','figure', ...
'NumberTitle','off', ...
'Position',[100 50 900 650], ...
'Resize','on',...
'Tag','maxminFig',...
'WindowButtonDownFcn','xy = get(gca,''CurrentPoint'');');
obj2.control2(1) = uicontrol('Parent',figmaxmin, ...
'Units','pixels', ...
'Style', 'pushbutton','Callback','newmaxmin(xy,''replacemax'')', ...
'ForegroundColor',[1 1 1], ...
'BackgroundColor',[1 0 0], ...
'ListboxTop',0, ...
'Position',[130 15 80 25], ...
'String',' Déplacer Max', ...
'Tag','Newmax');
obj2.control2(8) = uicontrol('Parent',figmaxmin, ...
'Units','pixels', ...
'Callback','newmaxmin(1,''fermer'')', ...
'ListboxTop',0, ...
'ForegroundColor',[0 0 0], ...
'BackgroundColor',[1 1 1], ...
'Position',[750 15 60 25], ...
'String','Fermer', ...
'Tag','Fermer');
Answers (1)
Kevin Phung
on 17 Jan 2019
Edited: Kevin Phung
on 17 Jan 2019
0 votes
You can assign a callback to the 'WindowKeyPressFcn' for your figure.
implement code to that callback that will evaluate the char that is pressed and will call another callback function (for example, your newmaxmin(xy,''replacemax'')).
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!