The callback of the editable text box will be executed when
· the focus moves to another component from the edit text
· with edit text in focus, the enter key (Enter + Ctrl in case of multiple line input support) is entered
There is no callback function that operates only when the focus shifts, but as an alternative, you can use the way which identifying the last key entered in the Callback function. If it is not the "Enter" key, you can define that the focus has shifted.
The sample code below is an example.
In the editable text box Callback function, identify the last entered key using the Figure's CurrentCharacter property. This will change the processing of the callback when pressing the Enter key in the editable text box and moving the focus.
(edit_off_samp.m)
function edit_off_samp
h_figure = figure;
h_edit = uicontrol('Style','edit','Callback',@edit_callback);
function edit_callback(src,event)
CK = get(h_figure, 'CurrentCharacter');
if isequal(double(CK),13)
disp('Pressed Enter Key')
else
disp('Focus off')
end
end
end
Best Answer