How to prevent a figure window to automatically take focus?
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 4 Mar 2016
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.
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!