A batch file that detects keystrokes. as?

im constructing a collection of video games for the command line (for example, business with or without a deal, tic tac toe, racing, maze, puzzle, connection four, wack a mole, etc.), however it would really make it easier for me if I could do so so that when the user makes a choice (for example, which direction to move in the game), as soon as they press the arrow keys, he performs the following IF statements. Instead of pressing enter after each selection. sort of...

:one1 set /p direction1= : IF %direction1%== {ARROW KEY LEFT} goto two2 IF %direction1%== {ARROW KEY RIGHT} goto three3 IF %direction1%== {ARROW KEY UP} goto four4 IF %direction1%== {ARROW KEY DOWN} goto five5 goto one1 

Any ideas?

+4
source share
3 answers
 :start choice /c:HPKM /n "Move with arrow keys" if "%errorlevel%"=="1" {COMMAND} if "%errorlevel%"=="2" {COMMAND} if "%errorlevel%"=="3" {COMMAND} if "%errorlevel%"=="4" {COMMAND} 
+3
source

It depends on your version of Windows.

If you use Vista, you can use the selection to get individual keys directly, but with a clean batch, it seems impossible to detect the arrow keys.

EDIT

 :one1 choice /c awsd /n /m "MOVE with ASD w" IF %errorlevel%==1 goto two2 IF %errorlevel%==2 goto three3 IF %errorlevel%==3 goto four4 IF %errorlevel%==4 goto five5 goto one1 
+5
source

http://winsupport.org/packages/choice.exe

This is a customizable selection that allows you to use the arrow keys.

they are used like this: choice / c: HPKM / n "Move with arrows"

The only problem is that you can also use H, P, K and M ...

0
source

All Articles