From: exosceleton on
When checking gco an editbox does not become the gco when clicked on.
Only after adding to the editbox (by pressing a key) does the editbox become the current object.

So now when using windowkeypress function with a gco check to handle "keyboard shortcuts" for my gui, the first key entered still activates the defined keyboard shortcut (not desired), while on subsequent keystokes the letter is just added to the editbox and the shortcut is ignored (as desired).

Why does the editbox not become current object when clicked on?

Any ideas how to let my windowkeypress reliably ignore keypresses when entered in an editbox?

(i first tried the buttondownfcn of the editbox to signal activation of the editbox, but that only activates in a 5 px border of the box)
From: Jan Simon on
Dear Exosceleton,

I confrim this behaviour for Matlab 2009a:
figure('WindowKeyPressFcn', 'disp(gco)');
uicontrol('Style', 'edit');
Now pressing a key replies the figure handle. When the edit field is entered, the first keystroke replies the figure handle, the second and all following key strokes reply the uicontrol's handle.

If you use the KeyPressFcn of the figure to catch keys, you still have the problem, that e.g. buttons keep the focus after they have been pressed and the window does not get any key events anymore.
At least until Matlab 2009a, the command "figure(FigureHandle)" does not gain the focus again, in opposite to the documentation.

Kind regards, Jan
From: exosceleton on
hello Jan,
i switched from Keypressfcn to windowkeypressfcn when i needed windowskeyreleasefcn.

Before i set the keypressfcn of all buttons = keypressfcn of the figure at program start, but that was not ideal.

Anyway, i don't understand why the editbox does not become the current object right away. I can see no use in waiting for a keystroke when i've allready clicked it, and the cursor is in the editbox.

cheers,
Exo
From: Jan Simon on
Dear exosceleton,

> Anyway, i don't understand why the editbox does not become the current object right away.

Let me try to explain this: I'd call this a "bug".
Although Yair has publsihed some Java tricks to manipulate the underlying callbacks of the edit UICONTROL, I'd be very careful with using such undocumented features. As far as I remember, the callback's name was "FocusGainedCallback", but could have changed (or change in the next release?) to "FocusGainCallback". Funny.
I'd recommend to ask "support(a)mathworks.com", see "send a bug report".

Good luck, Jan