.
Hello again CMD folk.
How do I request a key press, but only for a limited amount of time? e.g
Press any key now to boot from CD-ROM...
Cheers.
User input delay?
Moderator: DosItHelp
Re: User input delay?
Use the CHOICE command. Native to various versions of Windows and choice clones downloadable for OS that don't have it.
CHOICE version 4.1, Copyright (C) 1994--2003 Jim Hall, jhall@freedos.org
Waits for the user to press a key, from a list of choices
Usage: CHOICE [ /B ] [ /C[:]choices ] [ /N ] [ /S ] [ /T[:]c,nn ] [ text ]
/B - Sound an alert (beep) at prompt
/C[:]choices - Specifies allowable keys. Default is: yn
/N - Do not display the choices at end of prompt
/S - Be case-sensitive
/T[:]c,nn - Automatically choose key c after nn seconds
text - The text to display as a prompt
Re: User input delay?
You may use my GetKey auxiliary program to do that; search for GetKey.exe.hex in this post.
If you just want to wait for a key, then CHOICE command is a better option.
However, this method allows you to execute other things while the program waits. For example ReadLineTime subroutine (in above mentioned post) allows to limit the time to read a complete line of text and show the remaining time in the prompt string.
Antonio
Code: Select all
:GetKeyTime seconds
set seconds=%1
set lastTime=%time:~0,-3%
:wait
GetKey /N
if %errorlevel% neq 0 set seconds=0
if %lastTime% neq %time:~0,-3% (
set lastTime=%time:~0,-3%
set /A seconds-=1
)
if %seconds% gtr 0 goto wait
exit /B
However, this method allows you to execute other things while the program waits. For example ReadLineTime subroutine (in above mentioned post) allows to limit the time to read a complete line of text and show the remaining time in the prompt string.
Antonio
Re: User input delay?
.
Thanks Antonio. That's some cool stuff!
And thank you Foxi, as always.
Thanks Antonio. That's some cool stuff!
And thank you Foxi, as always.