MATLAB: How to update editbox uicontrol string during keypressfcn

uicontrol editbox keypressfcn string

Hi,
I have an editbox uicontrol that has a KeyPressFunction that would need to read what has been typed into the uicontrol. How can I make the KeyPressFunction to read the typed text? If I use
get(gcbo,'String')
it returns the string from before pressing any keys / since the last Callback event (in other words whatever the string was after I last pressed enter or clicked away from the editbox).
I want for the editbox to read the string when I press the downarrow key and act according to what has been written.
Thanks in advance, EK

Best Answer

Try this code as a workaround:
function test
close all
uicontrol('Style','Edit','String','matlab','KeyPressFcn',@clbck)
function clbck(src,evnt)
if isequal(evnt.Key,'downarrow')
import java.awt.Robot;
import java.awt.event.KeyEvent;
robot=Robot;
robot.keyPress(KeyEvent.VK_ENTER);
pause(0.01)
robot.keyRelease(KeyEvent.VK_ENTER);
disp(get(src,'String'));
end