request user to press enter key

조회 수: 57 (최근 30일)
genesis
genesis 2013년 10월 21일
댓글: Arturo Moncada-Torres 2013년 10월 23일
i want to request the user to press Enter before the program continue on execution. is it possible to assign only a button Enter and the rest is ignored?

답변 (1개)

Arturo Moncada-Torres
Arturo Moncada-Torres 2013년 10월 21일
편집: Arturo Moncada-Torres 2013년 10월 21일
You can try Jos's getkey function. What this function does is read the keystroke a user inputs. Therefore, you can condition the input until you get an enter, something like this:
keypressed = getkey;
while keypressed ~= 13 % 13 is the equivalent to the "enter" key.
disp('Enter was not pressed. Try again.');
keypressed = getkey;
end
disp('Congratulations! Enter was pressed :) .');
  댓글 수: 2
Jos (10584)
Jos (10584) 2013년 10월 21일
You can simplify this a little, as there is no need for a variable:
while getkey ~= 13,
...
end
(and thanks Arturo, for pointing to my submission, it's appreciated)
Arturo Moncada-Torres
Arturo Moncada-Torres 2013년 10월 23일
You are totally right, although I used the extra variable for clarity.
It is a great submission, you deserve it ;)

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

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by