flushing the keyboard input after a pause.

16 ビュー (過去 30 日間)
Jon Rozeay
Jon Rozeay 2022 年 11 月 1 日
回答済み: Jon Rozeay 2022 年 11 月 2 日
Hello,
I need to ignore the possible keyboard input during a pause. So for example:
i1 = input(' Enter first number : ')
pause(10)
i2 = input(' Enter second number : ')
I would like to ignore all the number that has been enter during the 10 second break.
So far, i2 will take whatever first number has been enter after i1.
This is driving me crazy thanks for your help,

採用された回答

Star Strider
Star Strider 2022 年 11 月 1 日
I generally do not use input, preferring inputdlg instead.

その他の回答 (2 件)

Jan
Jan 2022 年 11 月 1 日
The command window does not offer a way to flush the input buffer. But this window is a bad way to implement a user interface, if a specific behavior is wanted.
Create your own GUI instead. Then you have full control over the focus, the contents of edit fields and the behavior during a pause. The command window is not useful as a general prupose GUI.

Jon Rozeay
Jon Rozeay 2022 年 11 月 2 日
Great thanks a lot Jan and Star Strider, that helps a lot.
So far I have found this "clunky" solution;
i1 = input('Enter #1: ');
pause(5)
delta_time = 0;
while delta_time<0.1
tic
i2 = input('Enter #2: ');
delta_time = toc;
end
because all the number that I will enter during the pause(5) will be immediatly be loaded into i2, so by looking at the time it takes (between tic and toc) I can detect if it was a really answer or not.

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by