How to tell how an uieditfield was exited?

9 views (last 30 days)
I have a uieditfield field for text input.
There seem to be at least three ways to indicate to the app that we are finished entering information into this field. The ValueChangedFcn is called when (1) the user presses Enter, (2) the user presses Tab, or (3) the user changes from the app to another program running on the computer.
Is there a way to figure out which of these three events occured? In particular, I'd like to catch (3) and ignore processing the current value of the field for the moment.

Accepted Answer

Antonio Hortal
Antonio Hortal on 24 Jan 2021
Edited: Antonio Hortal on 24 Jan 2021
I might be wrong, but you could try getting the CurrentKey property of the figure
function editFieldValueChangedCallback(src,evt)
fig = ancestor(src,'figure');
switch get(fig,'CurrentKey')
case 'return'
disp('enter was pressed!')
disp('the user changed focus!')
David Aronstein
David Aronstein on 26 Jan 2021
I beg your pardon, Antonio! I tried your original solution again today in both R2019a and R2020a and it worked perfectly, thank you!! I don't know what I did wrong when I tried this and wrote back yesterday.

Sign in to comment.

More Answers (1)

Bhargavi Maganuru
Bhargavi Maganuru on 18 Feb 2020
After typing in the edit field, if you click anywhere outside the edit field, editFieldValueChanged callback will be triggered.
Add the following line of code in the callback function.
disp("exited from editfield");
So whenever this message is displayed, user has clicked outside the app.
Hope this helps!

Sign in to comment.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!