default behaviour of key press callback for matlab figure

6 vues (au cours des 30 derniers jours)
Ray Lee
Ray Lee le 16 Jan 2020
Commenté : Ray Lee le 17 Jan 2020
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?

Réponse acceptée

Guillaume
Guillaume le 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

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by