4.83333

4.8 | 6 ratings Rate this file 163 downloads (last 30 days) File Size: 1.93 KB File ID: #8297

GetKeyWait

by Jos

 

16 Aug 2005 (Updated 23 Apr 2009)

Code covered by BSD License  

Wait a certain time for a single keypress (v2.0, apr 2009).

Download Now | Watch this File

File Information
Description

GETKEYWAIT - get a key within a time limit
    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.
 
   See also input,
            getkey (FileExchange)

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
getkey

MATLAB release MATLAB 6.5 (R13)
Other requirements works on most ML releases
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
16 Aug 2005 urs (us) schwarz

in need of some re-engineering as it creates a new timer object every time it is called, which could be deleterious when used in a long loop, for instance.

26 Feb 2006 Inese Steinbahs

Thank You! This function worked out for my program wounderfully!

17 May 2007 Joseph Hollmann

Great submission

27 May 2008 Iohan Sandoval

very good job! thanks

26 Jun 2008 kk kk

thank you...fantastic work

15 Sep 2009 Ehsan Negahbani

Great. Thank you Jos.
Is it possible to prevent the appearance of figure tab in the task bar?
I'm calling your function in a loop every second, and it works well, but there is continuous blinking between command window and windows task bar as your code opens and closes a figure window each time. I tried to off the 'visible' property of the figure, but it was not working...

29 Oct 2009 Jesse Hopkins

Just what I was looking for

Please login to add a comment or rating.
Updates
17 Aug 2005

Timer object was not deleted which could cause problems after (many) repetitive calls. Thanks to us.

17 Aug 2005

Timer object was not deleted which could cause problems after (many) repetitive calls. Thanks to us.

17 Aug 2005

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.

23 Apr 2009

updated checks and output

Tag Activity for this File
Tag Applied By Date/Time
keypress Jos 22 Oct 2008 07:55:57
kbhit Jos 22 Oct 2008 07:55:57
input Jos 22 Oct 2008 07:55:57
timed Jos 22 Oct 2008 07:55:57
getkey Jos 22 Oct 2008 07:55:57
pause Jos 22 Oct 2008 07:55:57
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com