default behaviour of key press callback for matlab figure

16 visualizaciones (últimos 30 días)
Ray Lee
Ray Lee el 16 de En. de 2020
Comentada: Ray Lee el 17 de En. de 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?

Respuesta aceptada

Guillaume
Guillaume el 16 de En. de 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

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by