Kah - I think that part of the problem is that the String property of the edit text control is not updated until focus is set to some other control. So no matter how many characters you enter into the text box, your call to
get(handles.edit1,'String')
will always return an empty matrix until focus has been released at this control and focus set to another control.
You can try something like the following which "registers" character key presses in your edit1 control and shifts focus to edit2 after the fifth character key press.
function edit1_KeyPressFcn(hObject, eventdata, handles)
if ~isempty(eventdata.Character)
if ~isfield(handles,'charPressCount')
handles.charPressCount = 0;
end
handles.charPressCount = handles.charPressCount + 1;
if handles.charPressCount == 5
uicontrol(handles.edit2);
handles.charPressCount = 0;
end
guidata(hObject,handles);
end
Note how we check to see if eventdata.Character is empty or not. If the former, then we ignore the key press. Else if the latter, then we increment the counter in handles to keep track of how many character key presses have been made. Once we get to the fifth one, we shift focus to the edit2 control.
Try the above and see what happens!
Best Answer