我可以使用Cmd中的计时器创建'set / p“”='命令吗?(Can I create a 'set /p “”=' command with a timer in Cmd?)
我想为'set / p“”='命令创建一个计时器,这样如果您不在所需的时间空间中输入某些内容,它会移动到不同的标签。
例如。
echo You have 3 seconds to type 'go' (??if not typed in 3 seconds goto fail??) set /p input= if %input%==go goto win goto fail是否可以命令程序在'set / p'之前设置3秒定时器? 没有将它与C#等另一种语言混合?
I want to create a timer for the 'set /p ""=' command so that if you don't input something in the required time space it moves to a different label.
Eg.
echo You have 3 seconds to type 'go' (??if not typed in 3 seconds goto fail??) set /p input= if %input%==go goto win goto failIs it possible to command the program to set a 3 second timer before the 'set /p'? Without mixing it with another language like C# etc?
最满意答案
Squashman的建议也是我想到的最好的建议。 保存以下.bat脚本并运行它,并查看它是否提供了您想到的用户体验。
@echo off setlocal set /P "=You have 3 seconds to type 'go': "<NUL rem // capture an extended character as a default option for "choice" for /f %%I in ('forfiles /p "." /m "%~nx0" /c "cmd /c echo 0x99"') do set "char=%%~I" rem // for each letter in "go"... for %%I in (g o) do ( choice /c %%I%char% /t 3 /d %char% >NUL rem // Extended character probably isn't on the keyboard. rem // If the result was the extended char, it was timed out. if errorlevel 2 goto fail rem // visual response of user input w/o new line set /P "=%%I"<NUL ) echo; echo You did it! pause & goto :EOF :fail echo; echo Too slow. pauseSquashman's suggestion is the best one that comes to mind for me as well. Save the following .bat script and run it, and see whether it offers the user experience you had in mind.
@echo off setlocal set /P "=You have 3 seconds to type 'go': "<NUL rem // capture an extended character as a default option for "choice" for /f %%I in ('forfiles /p "." /m "%~nx0" /c "cmd /c echo 0x99"') do set "char=%%~I" rem // for each letter in "go"... for %%I in (g o) do ( choice /c %%I%char% /t 3 /d %char% >NUL rem // Extended character probably isn't on the keyboard. rem // If the result was the extended char, it was timed out. if errorlevel 2 goto fail rem // visual response of user input w/o new line set /P "=%%I"<NUL ) echo; echo You did it! pause & goto :EOF :fail echo; echo Too slow. pause
更多推荐
发布评论