如何在批处理脚本中使用箭头键? [英] How to work Arrow Keys in Batch Scripting?

查看:154
本文介绍了如何在批处理脚本中使用箭头键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用带有特殊键的CHOICE

示例:CHOICE/n/s/c:qQ按下[Page Down]键或按[q]退出:

以下是这些特殊键的列表:

27 [Esc] 08 [Back Space]

R [插入] G [首页] I [上一页]
S [删除] O [结束] Q [下一页]

H [向上箭头]
K [向左箭头] P [向下箭头] M [向右箭头]

; [F1] = [F3]
? [F5] @ [F6] A [F7] B [F8]
C [F9] D [F10] 133 [F11] 134 [F12]

我从此链接 http://users.cybercity.dk/~bse26236/batutil/help中获得了该代码/CHOICE_E.HTM [ ^ ]

如何在批处理文件中使用这些代码?示例情况将是..
如果我按向左箭头,它将进入另一个类似的批处理文件.请帮助..

Using CHOICE with special keys

Example: CHOICE /n/s/c:qQ Hit the [Page Down] key or press [q] to quit:

The following is the list of those special keys:

27 [Esc] 08 [Back Space]

R [Insert] G [Home] I [Page Up]
S [Delete] O [End] Q [Page Down]

H [UP Arrow]
K [Left Arrow] P [Down Arrow] M [Right Arrow]

; [F1] = [F3]
? [F5] @ [F6] A [F7] B [F8]
C [F9] D [F10] 133 [F11] 134 [F12]

I got that code from this link http://users.cybercity.dk/~bse26236/batutil/help/CHOICE_E.HTM[^]

How to use those codes in batch file? Example situation would be..
If I press arrow left it will goto another batch file something like that. Pls help..

推荐答案

批处理文件似乎无法实现.一种明显的解决方法是编写或查找可以从批处理文件运行的控制台应用程序,但是……这样做值得吗?我不这么认为吗?如果批处理文件可以在任何系统中工作,而无需其他实用程序,尤其是仅为扩展批处理功能而编写的实用程序,则它们具有很大的价值.

顺便说一句,您可以轻松了解批处理文件可以执行的所有操作.为此,您可以在与系统上的批处理文件功能有关的所有主题上自动构建帮助文件.要获取它,您需要运行此批处理:

It does not seem possible with batch files. The apparent workaround it to write or find a console application which you could run from your batch file, but… does it pay of to bother about it? I don''t think so? The batch files have considerable value if they can work in any system, without additional utilities, especially those written only for the purpose of extending batch functionality.

By the way, you can easily learn everything batch files can do. For this purpose, you can automatically build a help file on all topics related to batch file functionality on your system. To get it, you need to run this batch:

@ECHO OFF
IF "%OS%"=="Windows_NT" SETLOCAL DISABLEDELAYEDEXPANSION

:: Version number for this batch file
SET MyVer=1.40

:: Display "about"
ECHO.
ECHO AllHelp.bat,  Version %MyVer% for Windows NT 4 / 2000 / XP
ECHO Generate an HTML help file for "all" available commands
ECHO.
ECHO Note:
ECHO This batch file uses the redirected output of the HELP command to generate the
ECHO HTML file. Because some commands use "special" characters like ^&, ^<, and ^> in
ECHO their help screen, not all output is displayed correctly in the browser.
ECHO Known issues: skipped ^<space^> "tag" in CMD's special character list and skipped
ECHO \^<xyz and xyz\^> word position references in FINDSTR's output.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO.
ECHO Improved white space handling by Johan Parlevliet
ECHO Further improvements for NT 4 by Ulf Lindb„ck
ECHO.
ECHO.
ECHO.

IF NOT "%OS%"=="Windows_NT" SET MyVer=
IF NOT "%OS%"=="Windows_NT" GOTO End

:: Store current code page and then set code page for European languages
FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%A) DO SET CHCP=%%B
CHCP 1252 >NUL 2>&1

:: Start writing HTML file
ECHO Writing HTML header . . .
> allhelp.htm ECHO ^<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"^>
>>allhelp.htm ECHO ^<HTML^>
>>allhelp.htm ECHO ^<HEAD^>
:: Read Windows version using VER command
FOR /F "tokens=1 delims=[" %%A IN ('VER') DO SET Ver=%%A
FOR /F "tokens=1* delims= " %%A IN ('ECHO.%Ver%') DO SET Ver=%%B
:: Read latest Service Pack from registry
CALL :GetSP
>>allhelp.htm ECHO ^<TITLE^>Help for all %Ver%%SP% commands^</TITLE^>
>>allhelp.htm ECHO ^<META NAME="generator" CONTENT="AllHelp.bat, Version %MyVer%, by Rob van der Woude"^>
>>allhelp.htm ECHO ^</HEAD^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<BODY^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A NAME="Top"^>^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<CENTER^>
>>allhelp.htm ECHO ^<H1^>%Ver%%SP% commands^</H1^>
FOR /F "tokens=* delims=" %%A IN ('VER') DO SET Ver=%%A
>>allhelp.htm ECHO ^<H3^>%Ver%^</H3^>
>>allhelp.htm ECHO ^</CENTER^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^ ^</P^>
>>allhelp.htm ECHO.

ECHO Creating command index table . . .
SET FirstCell=1
>>allhelp.htm ECHO ^<TABLE BORDER="0"^>
:: Skip 1 or 2 lines of HELP command's header
FOR /F "tokens=1 delims=[]" %%A IN ('HELP ^| FIND /N "."') DO IF %%A LEQ 2 SET Skip=+%%A
:: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
:: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
:: %Skip% skips 1 or 2 lines of HELP command's header
FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispLine "%%A"
>>allhelp.htm ECHO ^</TD^>^</TR^>
>>allhelp.htm ECHO ^</TABLE^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^ ^</P^>
>>allhelp.htm ECHO.

ECHO Writing help for each command:
:: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
:: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispFull "%%A"

ECHO Closing HTML file
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<DIV ALIGN="Center"^>
>>allhelp.htm ECHO ^<P^>This HTML file was generated by:^<BR^>
>>allhelp.htm ECHO ^<B^>AllHelp.bat^</B^>, Version %MyVer%
>>allhelp.htm ECHO for Windows NT^ 4^ /^ 2000^ /^ XP^<BR^>
>>allhelp.htm ECHO Written by Rob van der Woude^<BR^>
>>allhelp.htm ECHO ^<A HREF="http://www.robvanderwoude.com"^>http://www.robvanderwoude.com^</A^>^</P^>
>>allhelp.htm ECHO ^</DIV^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^</BODY^>
>>allhelp.htm ECHO ^</HTML^>

ECHO.
ECHO An HTML help file "allhelp.htm" has been created and stored in the current
ECHO directory.
ECHO.
ECHO Now starting display of "allhelp.htm" . . .
START "AllHelp" allhelp.htm

:: End of main batch program
CHCP %CHCP% >NUL 2>&1
ENDLOCAL
GOTO:EOF


:: Subroutines


:DispLine
SET Line=%1
SET Line=%Line:(=^(%
SET Line=%Line:)=^)%
SET Line=%Line:"=%
SET Command=%Line:~0,8%
SET Command=%Command: =%
IF DEFINED Command CALL :DispCmdLine %Command%
FOR /F "tokens=1* delims= " %%a IN ('ECHO.%*') DO SET Descr=%%b
SET Descr=%Descr:"=%
>>allhelp.htm ECHO.%Descr%
GOTO:EOF


:DispCmdLine
IF "%FirstCell%"=="0" IF DEFINED Command (>>allhelp.htm ECHO ^</TD^>^</TR^>)
SET Command=%1
IF DEFINED Command (>>allhelp.htm ECHO ^<TR^>^<TH ALIGN="left" VALIGN="top"^>^<A HREF="#%Command%"^>%Command%^</A^>^</TH^>^<TD^>^ ^ ^ ^</TD^>^<TD^>)
SET FirstCell=0
SET Command=
GOTO:EOF


:DispFull
SET Line=%1
SET Command=%Line:~1,8%
SET Command=%Command: =%
IF DEFINED Command CALL :WriteFull %Command%
SET Command=
GOTO:EOF


:GetSP
SET SP=
:: Export registry tree to temporary file
START /WAIT REGEDIT.EXE /E "%Temp%.\%~n0.dat" "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
IF NOT EXIST "%Temp%.\%~n0.dat" GOTO:EOF
:: Read value of "CSDVersion" from temporary file
FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\%~n0.dat" ^| FIND /I "CSDVersion"') DO SET SP=%%~A
:: Check if value is valid
ECHO.%SP% | FIND /I "Service Pack" >NUL
IF ERRORLEVEL 1 SET SP=
DEL "%Temp%.\%~n0.dat"
:: Use a shorter notation
IF DEFINED SP SET SP=%SP:Service Pack=SP%
GOTO:EOF


:WriteFull
ECHO.  %1 . . .
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A NAME="%~1"^>^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<H2^>%1^</H2^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<PRE^>
>>allhelp.htm HELP %1
>>allhelp.htm ECHO ^</PRE^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A HREF="#Top"^>Back to the top of this page^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^ ^</P^>
>>allhelp.htm ECHO.
GOTO:EOF

:End



感谢Rob van der Woude和Johan Parlevliet.如果您希望得到的帮助中未列出的内容,则是不可能的.

—SA



Thanks to Rob van der Woude and Johan Parlevliet. If you want something not listed in the resulting help, it is not possible.

—SA


这篇关于如何在批处理脚本中使用箭头键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆