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!

 채택된 답변

Walter Roberson
Walter Roberson 2018년 5월 30일

1 개 추천

Yes, keypressfcn is suitable for this. The eventdata will have a structure for which the field Key will contain 'return' in this case.

댓글 수: 3

Douglas Anderson
Douglas Anderson 2018년 5월 30일
Thank you, Walter.
I am used to using the handles structure to pass information between functions, but not to eventdata. How do you get the information that they key has been pressed into the KeyPressFcn, and then from the KeyPressFcn associated with the done_button to the done_button Callback that then closes things out?
Thanks. By the way your help is so good -- have you written a MATLAB book?
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
Douglas Anderson
Douglas Anderson 2018년 5월 30일
Perfect! Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by