I want a button to be pressed in MATLAB GUI when Enter key is pressed. How to do it?

조회 수: 29 (최근 30일)
Hi,
I have a pushbutton added in my MATLAB GUI and I want it to be pressed whenever Enter key is pressed. How can I do that?

답변 (2개)

Nathan Greco
Nathan Greco 2011년 7월 7일
I do something similar to this. Use keypress functions, and check to see if the current character being pressed is the enter key (carriage return).
Assuming your main GUI figure is named figure1, write this in each keypress function in your GUI:
currChar = get(handles.figure1,'CurrentCharacter');
if isequal(currChar,char(13)) %char(13) == enter key
%call the pushbutton callback
end
Note that doing this will not let you type the enter key within your edit text, since any instance of the enter key will call the push button.
  댓글 수: 1
Arno Patrice
Arno Patrice 2013년 1월 14일
you have to add it to keypress of every active uicontrol (edit box for example) where you want it to act.

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


Doug Hull
Doug Hull 2011년 7월 7일
I doubt you can in any reasonable way.
You need to be more specific about "whenever the enter key is pressed", but I don't think you can do this.
A better question is "Why do you want to?" Please modify your question to answer this, DO NOT ADD IT as an answer to this question.
  댓글 수: 1
Matlab Help Seeker
Matlab Help Seeker 2011년 7월 7일
I have a two controls in a GUI.
1. An edit text control, where someone can enter a message.
2. A pushbutton, when pressed message is sent.
So, I want when someone writes a message, he presses a tab to move to pushbutton. This works fine.
Now, when he presses Enter key, the pushbutton is pressed and the message is sent.

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by