4

I am trying to add a time out to Set /p Var1= So far I have only found this piece of code from here.

@echo off
setlocal EnableDelayedExpansion
if "%1" NEQ "" goto %1

del enter.tmp 2>nul >nul
start /b cmd /c %0 :secondThread

:FirstThread
set n=0
echo Enter Text (5 seconds timeout):

:loop
set /a n+=1
ping -n 2 localhost > nul
if !n! LSS 5 (
    if not exist entER.tmp goto :loop
    < Enter.tmp (
        set /p input=
    )
    echo !input!
) ELSE (
    echo Timeout for input
)

exit /b

:secondThread
set /p var=
> enter.tmp echo !var!
exit /b

This piece of code works great except it stops the count down only when the input is entered. I would like the count down to stop when any key is pressed. I don't know if this is possible. Thanks

Community
  • 1
  • 1
  • Welcome to [SO]. What is the purpose of your batch? Choice has a timeout but only errorlevel as response maybe you could combine this with a set /p. –  Mar 25 '17 at 17:57
  • I am trying to get my batch file to update ever second by clearing the screen and putting the text back up but I still want to still have the option of inputting text. The code I have now the only way to type into it would be to type in between its reset which would be hard. – Anthony Jack Mar 25 '17 at 18:10
  • possible duplicate of http://stackoverflow.com/questions/17359345/timeout-for-user-decision-in-windows-batch-file –  Mar 26 '17 at 11:52
  • 2
    Possible duplicate of [Timeout for user decision in windows batch file](http://stackoverflow.com/questions/17359345/timeout-for-user-decision-in-windows-batch-file) –  Mar 26 '17 at 11:53
  • My question is very similar to this post but I'd like to have a text input not using a yes or no answer. I would also like the countdown to stop when a key is pressed not when the input is entered. – Anthony Jack Mar 30 '17 at 22:26

0 Answers0