如何使用箭头键作为批处理文件中的输入

时间:2013-05-17 16:40:18

标签: batch-file cmd windows-7 arrow-keys

我很好奇是否有办法使用键盘上的箭头键能够从它们接收输入并在批处理文件中使用此信息?谢谢 BURNE

1 个答案:

答案 0 :(得分:2)

有几种方法可以将箭头符号/键分配给变量,但是你不能将它们用作输入,因为它们是命令提示符中的操作按钮(移动光标并通过已执行的命令迭代)并且你无法检测到他们的压力。

修改

@echo off
CHCP 1251

::Define a Linefeed variable
set LF=^


::above 2 blank lines are critical - do not remove
endlocal

call :hexPrint "0x1a" upArrow
call :hexPrint "0x1b" downArrow
call :hexPrint "0x18" rightArrow
call :hexPrint "0x19" leftArrow

echo %upArrow%  %downArrow% %rightArrow% %leftArrow% 

goto :eof
:hexPrint  string  [rtnVar]
  for /f eol^=^%LF%%LF%^ delims^= %%A in (
    'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
  ) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
exit /b

这会将箭头设置为变量,但结果可能取决于您的CHCP。我已使用this as reference。如果没有forfiles