Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top