我在cmd批处理中使用超时事件,但是当它超时时,我如何捕获用户在事件上按下的键? 还是知道时间已经到了?
可能是这样的:
@echoecho "请按任意键继续,否则程序将退出"超时/t 5( if(timeout == true 和按键 != "null")( 转到继续 ) 否则 ( 退出 ))
P/S:很抱歉在这里使用了一些java代码,因为我仍然无法想象它在cmd批处理中是如何工作的(谷歌搜索了它,但仍然不能。
请帮忙,谢谢!
另一个选项是选择命令。
choice /c abcd /n /t 5 /d defaultchoice /m "Please press a or b or c or d to continue or Program will exit"
if errorlevel 1 set choice=a
if errorlevel 2 set choice=b
if errorlevel 3 set choice=c
if errorlevel 4 set choice=d
选择命令的缺点是你不能按任何键,你必须设置用户能够按下的所有键。不过,可能有更好的解决方案。
/t 表示超时
/d 表示默认选择,例如 /d a
/n 隐藏选项列表
/c abcd 将可用选项设置为 a、b、c 和 d
添加/cs 以区分大小写