how to use arrow keys as an input in a batch file

ⅰ亾dé卋堺 提交于 2019-12-20 02:44:06

问题


I was curious if there was a way to use the arrow keys on your keyboard to be able to receive input form them and use this information in a batch file? Thanks BurnE


回答1:


There a few ways that you can assign arrows symbols/keys to variable, but u can't use them as input as they are operational buttons in command prompt (move cursor and iterate trough the already executed commands) and you cant's detect their pressing.

EDIT:

@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

this will set the arrows to a variables , but result might depends on your CHCP.I've used this as reference .Will not work on XP if have no forfiles



来源:https://stackoverflow.com/questions/16614048/how-to-use-arrow-keys-as-an-input-in-a-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!