default behaviour of key press callback for matlab figure

조회 수: 17 (최근 30일)
Ray Lee
Ray Lee 2020년 1월 16일
댓글: Ray Lee 2020년 1월 17일
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?

채택된 답변

Guillaume
Guillaume 2020년 1월 16일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by