Effacer les filtres
Effacer les filtres

KeyPressFcn and WindowKeyPressFcn not working

5 vues (au cours des 30 derniers jours)
André
André le 29 Fév 2024
Commenté : André le 8 Mar 2024
I have a GUI (using the old figure, not uifigure). The figure has a KeyPressFcn to do some action.
So I have a pushbutton, and after clicking it I want to hide the button, so its callback turns off its visibility ('Visible', 'off').
When that happens, the KeyPressFcn (or WindowKeyPressFcn I also tried it) if the figure stops working. No matter what I do, I can't recover the focus.
So this is what I tried, and nothing worked, even with everything combined:
set(figHandle, 'CurrentObject', figHandle)
set(figHandle, 'CurrentObject', pushbuttonHandle)
figure(figHandle)
gco(figHandle)
gcf(figHandle)
figHandle.Visible = 'off'
figHandle.Visible = 'on'
drawnow
NOTHING WORKS.
Only way to make it work again is clicking the figure. But thats exactly what I DONT want to do. I must not click the figure after clicking the pushbutton, at least before the desired keypress.
However, if I enter debubg mode using breakpoints, then this works:
set(figHandle, 'CurrentObject', figHandle)
figure(figHandle)
But it does not work if not in debug mode. I don't understand this behaviour. I know removing visbility to objects have some strange side effects. But it should never remove permanently focus from a figure.
Why does it work in debugging mode, but not in normal mode?
Matlab R2020b
  2 commentaires
Voss
Voss le 29 Fév 2024
Rather than setting the pushbutton invisible in its callback, try setting its position to something outside the figure, e.g., [-10 -10 1 1], and see if that changes anything.
André
André le 8 Mar 2024
Its a possible option, maybe I will test it later.
I ended up using virtual mouse clicks using Java to recover the focus of the figure. I don't like such clumsy solutions, but thats the only way I figured out.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by