MATLAB: GUI Button with keyboard shortcut

guikeyboardpushbuttonuicontrol

Hi,
I have a button in a GUI. The user may press it to execute the Callback. Alternatively, I would like the user to be able to press a shortcut key (for example, 'c') to press the button instead of clicking to execute the same callback.
Any ideas how to do this?

Best Answer

Thanks Walter. I basically went with your solution.
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 'c'
task(MyButton, []);
end
end
Related Question