.bat文件中的可滚动列表

的ipodlover3354

是否可以在批处理文件中使用箭头键创建可滚动列表?选择一个之后,它可以执行以下操作:(goto result1)等吗?如果不可能,我只需要坚持让用户自己输入答案即可。

动作

下面的批处理文件使用了一个有趣的技巧,其中包括用列表中的元素填充DOSKEY历史记录。之后,将F7键发送到键盘,因此在执行SET / P命令时,先前的元素会显示在由DOSKEY管理的可滚动列表(菜单选择)中。

@if (@CodeSection == @Batch) @then


@echo off
setlocal EnableDelayedExpansion

rem Multi-line menu with options selection via DOSKEY
rem Antonio Perez Ayala

rem Define the options
set numOpts=0
for %%a in (First Second Third Fourth Fifth) do (
   set /A numOpts+=1
   set "option[!numOpts!]=%%a Option"
)
set /A numOpts+=1
set "option[!numOpts!]=exit"

rem Clear previous doskey history
doskey /REINSTALL
rem Fill doskey history with menu options
cscript //nologo /E:JScript "%~F0" EnterOpts
for /L %%i in (1,1,%numOpts%) do set /P "var="

:nextOpt
cls
echo MULTI-LINE MENU WITH OPTIONS SELECTION
echo/
rem Send a F7 key to open the selection menu
cscript //nologo /E:JScript "%~F0"
set /P "var=Select the desired option: "
echo/
if "%var%" equ "exit" goto :EOF
echo Option selected: "%var%"
pause
goto nextOpt


@end

var wshShell = WScript.CreateObject("WScript.Shell"),
    envVar = wshShell.Environment("Process"),
    numOpts = parseInt(envVar("numOpts"));

if ( WScript.Arguments.Length ) {
   // Enter menu options
   for ( var i=1; i <= numOpts; i++ ) {
      wshShell.SendKeys(envVar("option["+i+"]")+"{ENTER}");
   }
} else {
   // Enter a F7 to open the menu
   wshShell.SendKeys("{F7}");
}

上一个程序的输出示例:

以前程序的示例

上一个程序是Batch-JScript混合脚本;您可能会看到这篇文章中对混合脚本的解释,而这篇文章中对此程序的进一步描述。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章