Disabling keyboard output to the Command Window

13 views (last 30 days)
Hello all,
I am currently using catching keyboard input (using ginput) in a GUI to control figure properties, e.g., zoom, scroll, colouring, area selection. However, when I hold down a key for a while, the autorepeat causes the GUI figure to lose focus and the key letter to be displayed at the Command Window.
How do I disable (and re-enable) keyboard output to the Command Window?
Many thanks in advance,
James

Accepted Answer

Jan
Jan on 11 Apr 2011
How do you use GINPUT to control zoom etc? I think the KeyPressFcn or the WindowKeyPressFcn to be more useful - and they catch keystrokes before they are forwarded to the command line. See:
docsearch KeyPressFcn
  2 Comments
James Ong
James Ong on 12 Apr 2011
Thank you for bringing my attention to the fact that KeyPressFcn has the desired blocking of keyboard output to the Command Window when there is a callback associated with it.
The reason I chose _ginput_ is because I want to perform operations on an axes child of the figure window, and _ginput_ gives me the coordinates within the axes. The operations require reasonable precision in the position estimate of the pointer (e.g., pixel by pixel editing of an image), and the CurrentPoint property is subject to rounding error, meaning that if I calculate back to local coordinates within the axes, it's possible that the wrong pixel might be selected.
If there is no other obvious way, though, I'll probably implement things as you suggest.
James Ong
James Ong on 21 Apr 2011
OK, I've implemented things such that they work as I want.
1. I implemented an empty KeyPressFcn so that no keystrokes go through to the Command line.
2. I implemented an empty WindowButtonMotionFcn to force the CurrentPoint property to change when the cursor moves.
3. I used the following code to replace my usage of ginput:
if waitforbuttonpress
button = get(handles.viewer_figure, 'CurrentCharacter');
else
switch get(handles.viewer_figure, 'SelectionType')
case 'normal'
button = 1;
case 'alt'
button = 3;
otherwise
continue % I'm working inside a loop
end
end
temp_mouse_pos = get(get(handles.viewer_figure, 'CurrentAxes'), ...
'CurrentPoint');
clicked_col_raw = temp_mouse_pos(1,1);
clicked_row_raw = temp_mouse_pos(1,2);

Sign in to comment.

More Answers (0)

Categories

Find more on Data Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!