End Guide GUI with Enter Button

3 views (last 30 days)
Hello!
I have a simple GUIDE GUI that has four edit boxes to gather information, and a "Done" button at the bottom. I use uicontrol(handles.editbox1) to put the cursor at the top editbox, and the user can Tab down through the boxes and then to the Done button. At that point, the user can exit by clicking on the Done button, but it would be much cleaner to have them just press "Enter".
Is this properly done in the KeyPressFcn callback for handles.done_button? And do you just see if getkey == 13 in eventdata? I am not sure where this is documented!
Thanks!

Accepted Answer

Walter Roberson
Walter Roberson on 30 May 2018
Yes, keypressfcn is suitable for this. The eventdata will have a structure for which the field Key will contain 'return' in this case.
  3 Comments
Walter Roberson
Walter Roberson on 30 May 2018
Example:
but = uicontrol('style','push', 'String', 'Type here', 'keypressfcn', @(hObject, eventdata) disp(eventdata.Key))
In your situation, I would suggest:
function done_Callback(hObject, eventdata, handles)
finish_up(hObject, eventdata, handles);
function done_KeyPressFcn(hObject, eventdata, handles)
if strcmp(eventdata.Key, 'return')
finish_up(hObject, eventdata, handles);
end
where finish_up contains whatever content you would normally have put directly into done_Callback

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!