I have a batch file that loads on startup that presents the user with a "menu" of applications they can choose to load by typing the corresponding "menu number". How can we reduce user input, simplifying their selection, to automatically pass any key pressed to the command prompt without needing the Enter key to be pressed after their selection is typed? That is, if a user inputs 1, read that value as if the user had input 1 + Enter The constant here is that the menu only spans from 1-9
, so the input from the user will ever only be 1 character long (if that's at all relevant).
简而言之,菜单是如何呈现的以及如何处理用户输入:
:menu
echo [Menu]
echo.
echo [1] - PuTTy
echo [2] - Chrome (Google)
echo.
echo [0] - Exit
SET /P M=(:
IF %M%==1 goto choice1
IF %M%==2 goto choice2
IF %M%==0 goto choice0
:choice1
start "" "%ProgramFiles(x86)%\PuTTy\putty.exe"
goto menu
:choice2
start "" "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" www.google.com
goto menu
:choice0
exit
您可以使用Choice http://ss64.com/nt/choice.html为了这。
所以你的脚本将类似于:
:menu
echo [Menu]
echo.
echo [1] - PuTTy
echo [2] - Chrome (Google)
echo.
echo [0] - Exit
choice /c 120 /n /m (:
IF errorlevel 3 goto choice0
IF errorlevel 2 goto choice2
IF errorlevel 1 goto choice1
:choice1
start "" "%ProgramFiles(x86)%\PuTTy\putty.exe"
goto menu
:choice2
start "" "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" www.google.com
goto menu
:choice0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)