Actually this should move the focus to the figure:
Unfortunately this does not work - at least since Matlab 5.3.
The temporary disabling of an uicontrol, which is currently focussed, move the focus to its parent. If your GUI contains an uicontrol you can try this, after the drawing:
hObject = HandleOfTheButton;
set(hObject, 'enable', 'off');
set(hObject, 'enable', 'on');
This moves the focus to the button (or whatever) at first and to the figure afterwards.
But a problem remains: Whenever you click on the axes object, it gets the focus back and the figure's KeyPressFcn is not active anymore. Then it will be more reliable, if you add the KeyPressFcn to all objects, which allows to set this property.
The must be a Java callback, which allows to activate the figure, but I cannot test this currently:
jPeer = get(handle(gcf), 'JavaFrame');
jAxis = jPeer.getAxisComponent;
jWindow = jPeer.fFigureClient.getWindow;
Now you can study the methods:
Is there a "setFocus()" routine? If so and it works:
This is undocumented and you have to care for the fact, that this might not work with other Matlab releases. So include the command in a TRY-CATCH block and write a meaningful warning message if it fails.
[EDITED] It is:
jPeer = get(handle(gcf), 'JavaFrame')
[EDITED 2] Please send an enhancement request to TMW, if you want figure(gcf) to set the focus reliably.