Reputation: 165
I have a button in a GUI. which the user presses to execute a Callback. But, I would like the user to be able to press the up arrow key instead of clicking to execute the callback.
EDIT: I am using GUIDE to make the GUI
Upvotes: 2
Views: 4827
Reputation: 1623
Check out this thread:
http://www.mathworks.com/matlabcentral/answers/12034
Just slightly modifying the code from there to here (put the following in a file called testGUI.m
function testGUI
g = figure('KeyPressFcn', @keyPress)
MyButton = uicontrol('Style', 'pushbutton','Callback',@task);
function task(src, e)
disp('button press');
end
function keyPress(src, e)
switch e.Key
case 'uparrow'
task(MyButton, []);
end
end
end
Upvotes: 4