default behaviour of key press callback for matlab figure

6 views (last 30 days)
When press a key, matlab automatically brings the command window to the front.
But when I assign a customed keypressfcn to the figure, matlab only responds to the key press I defined in the callback function. Even when I press other keys, it does not swtich from figure to command window automatically.
How can I keep the automatic switching?

Accepted Answer

Guillaume
Guillaume on 16 Jan 2020
Matlab can't know which keys your callback care or doesn't care about, so your callback receives all the key presses and indeed the command window is no longer brought to the foreground.
In my opinion, it's not a good idea to rely on this behaviour. I wasn't even aware of it and personnally, I'd be annoyed if a GUI brought back a command window that I'd minimised.
Noneless, you can set the focus back to the command window within your callback by calling commandwindow:
function yourkeypresscallback(source, eventargs)
%some event handling code eg
if eventargs.Key == 'q' && isempty(eventargs.Modifier)
%do something
end
%now bring focus to command window
commandwindow;
end

More Answers (0)

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!