我在 cmd 中使用这个简单的菜单,在其中我用TAB键填充了我的 ECHO:
:MENU
ECHO select this by pressing 0
ECHO(
ECHO select this by pressing 1
ECHO(
SET /P ANSWER="press something:"
有没有办法填充SET /P ANSWER=
??的输出?
我尝试过TAB它和/或SPACE它,但不起作用。它看起来像这样:
select this by pressing 0
select this by pressing 1
press something:_
我希望它看起来像这样:
select this by pressing 0
select this by pressing 1
press something:_
答案1
您可以使用一些控制字符,例如退格键(U+0008
),如以下代码片段所示;提示:可以使用以下命令从键盘捕获单个按键choice
命令(见脚本)
@ECHO OFF
SETLOCAL EnableExtensions
rem get backspace character to BS variable
for /F %%a in ('echo prompt $H ^| cmd') do set BS=%%a
:MENU
ECHO(
ECHO select this by pressing 0
ECHO(
ECHO select that by pressing 1
ECHO(
rem ↓ this character is deleted in output by backspace
SET /P "ANSWER=X%BS% press something: "
ECHO(
echo "%ANSWER%" entered; another approach using CHOICE command:
ECHO(
CHOICE /C 01 /N /M "X%BS% Select [0] this or [1] that: "
输出:
==> D:\bat\SU\1324661.bat
select this by pressing 0
select that by pressing 1
press something: s
"s" entered; another approach using CHOICE command:
Select [0] this or [1] that: 1
==>