Version 3.0 (2,18 KB) von Jos (10584)
Wait a certain time for a single keypress
Aktualisiert 11 Feb 2019

Lizenz anzeigen

CH = getkeywait(P) waits for a keypress for a maximum of P seconds. P
should be a positive number. CH is a double representing the key
pressed key as an ascii number, including backspace (8), space (32),
enter (13), etc. If a non-ascii key (Ctrl, Alt, etc.) is pressed, CH
will be NaN. If no key is pressed within P seconds, -1 is returned,
and if something went wrong during excution 0 is returned.
Without argument, getkeywait waits until a key is pressed.

[CH, RT] = getkeywait(..) returns the response time in seconds in RT.

disp('Press a key within 5 seconds') ;
[CH, DT] = getkeywait(5)

See also input, ginput, waitbar, msgbox
getkey (file Exchange)

Authors note: This file was created in 2005 and is still working ;-)

Zitieren als

Jos (10584) (2024). getkeywait (, MATLAB Central File Exchange. Abgerufen .

Kompatibilität der MATLAB-Version
Erstellt mit R2018b
Kompatibel mit allen Versionen
Windows macOS Linux
Mehr zu Argument Definitions finden Sie in Help Center und MATLAB Answers

Inspiriert von: getkey

Inspiriert: waitinput

Community Treasure Hunt

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

Start Hunting!
Version Veröffentlicht Versionshinweise


changed some figure properties; added check for figure existence

updated checks and output

The timer object existed beyond the scope of the function, which could be problematic when the function is called often, e.g., in a long loop.