How to prevent a figure window to automatically take focus?
1 次查看(过去 30 天)
显示 更早的评论
When a figure is plotted, its window gets the focus and any characters typed appear to be interpreted by this Window's code instead of going to the console. The default action seems to be that the plotted trace vertically expands.
This is extremely annoying when interactively typing at the keyboard (zooming is normally done with the mouse). How to turn off this behavior?
0 个评论
回答(1 个)
Walter Roberson
2016-3-4
A call to figure() that creates a new figure always gives focus to the figure.
Calls to figure() to create a new figure are automatically done if an axes is created without an active current figure, and axes are created automatically if graphics drawing operations such as plot() are requested when there is no current axes. You therefore do not have to be calling figure() yourself for this automatic-focus to apply.
At least up to R2014a, if you type while a figure has focus, the typing will be forwarded to the command window unless there is a KeyPressFcn or KeyReleaseFcn or WindowKeyPressFcn or WindowKeyReleaseFcn in effect, or unless a uicontrol has focus and the uicontrol has an active KeyPressFcn.
Some functions and special drawings install uimodemanager that grab the KeyPressFcn or WindowKeyPressFcn . zoom, pan, and datacursor tend to do that. I have encountered problems with that in the past. Those can be difficult to work around.
When you encounter problems such as this, it is usually easiest to deliberately give the focus away to a different uicontrol or different figure.
There might be something on undocumentedmatlab about setting the root CurrentFigure property to be empty; there is no obvious method.
It sounds as if you are working at the command line and so would prefer a setting that would automatically tell new figures to not get keyboard focus if they happen to have a *KeyPressFcn . There is no setting for that.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!