检测击键的批处理文件。如何?

发布于 2024-10-06 05:54:35 字数 412 浏览 0 评论 0原文

我正在为命令行设计一系列视频游戏(例如交易或不交易、井字棋、赛车、迷宫拼图、连四、打地鼠等),但是如果我可以的话,这真的会让我的事情变得更容易使得当用户做出选择(例如在游戏中移动的方向)时,只要他们按下箭头键,就会执行后面的 IF 语句。而不必在每次选择后按 Enter 键。类似...

: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

有什么想法吗?

im designing a collection of video games for the command line (such as deal or no deal, tic tac toe, racing, maze puzzle, connect four, wack a mole, etc.) however it would really make things easier for me if i could make it so that when the user makes a selection (such as what direction to move in the game) , that as soon as they press the arrow keys then it carries out the IF statements that follow. Instead of having to press enter after each selection. something like...

: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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海拔太高太耀眼 2024-10-13 05:54:35

这取决于您的 Windows 版本。

如果你使用Vista,你可以使用choice直接接收单个按键,但是使用纯批量似乎无法检测到方向键。

编辑

:one1
choice /c awsd /n /m "MOVE with A S D w"
IF %errorlevel%==1 goto two2
IF %errorlevel%==2 goto three3
IF %errorlevel%==3 goto four4
IF %errorlevel%==4 goto five5
goto one1

It depends of your windows version.

If you use Vista, you can use choice to receive single keys directly, but with pure batch it seems not to be possible to detect the arrow keys.

EDIT

:one1
choice /c awsd /n /m "MOVE with A S D w"
IF %errorlevel%==1 goto two2
IF %errorlevel%==2 goto three3
IF %errorlevel%==3 goto four4
IF %errorlevel%==4 goto five5
goto one1
献世佛 2024-10-13 05:54:35
: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}
: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}
贵在坚持 2024-10-13 05:54:35

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

这是一个自定义选择,允许要使用的箭头键。

它们的使用方式如下:选择 /c:HPKM /n "用箭头键移动"

唯一的问题是你也可以使用 H、P、K 和 M...

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

That is a custom choice that allows for arrow keys to be used.

they are used like so: choice /c:HPKM /n "Move with arrow keys"

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文