Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

GUI Keyboard Commands HELP

Asked by John on 11 Dec 2012

Hi,

I have a complex GUI, but I have what I think is a fairly simple problem.

I have keyboard commands set to various commands including button presses (This is because eventually the GUI needs to operate as keyboard only). The problem I have is that I have to manually click the figure window before it allows the GUI to recognise that I'm pressing keyboard buttons.

Is there a way to set the current figure to be the focus so that I don't need to use the mouse?

Thanks in advance!

JD

0 Comments

John

Products

No products are associated with this question.

1 Answer

Answer by Sean de Wolski on 11 Dec 2012
Accepted answer

Yes!

You need to steal focu back to the figure from whatever uicontrol/uipanel/axes/etc. has stolen it.

To do this, at the end of a callback function for one of these widgets:

        set(H, 'Enable', 'off');
        drawnow;
        set(H, 'Enable', 'on');

Where H is the handle to that widget.

4 Comments

Sean de Wolski on 11 Dec 2012

You don't want to disable the figure; You want to disable the widget that stole focus from the figure!

You can use this file as a reference:

boggle-v2-0

I had to take the above steps any time one of the widgets stole focus from the figure.

Jan Simon on 12 Dec 2012

@John: In Sean's example, H is the handle of the uicontrol or axes object, not the handle of the figure.

John on 19 Feb 2013

Thanks Saun and Jan. Much appreciated. I've been working on other stuff until now so sorry for the delay in my thanks!

Sean de Wolski

Contact us