在循环中批量捕获击键

Catching keystroke during loop in batch

作为我的批处理编程的小培训,我最初是按照想法制作一个小型老虎机。你可以给你的硬币,数字会快速通过,当你按下一个按钮时,数字应该会停止在当前值。如果它们都一样,砰,你中奖了!

我现在的问题是循环期间的击键捕获。我已经想到了类似选择命令的东西,但是程序会在每个循环中停止等待键盘输入,这不会让游戏一直等待很烦人,但也很无聊,因为你可以检查你是否想点击一个特定按钮停止。

另一个想法是

set /p foobar=

然后用 !SendKeys! 模拟一个 Enter-Stroke(代码中包含所有必要的东西),忘记输入后已经发送输入...

有没有办法在 ONE 批处理文件中完成?还是我必须想出另一个来模拟击键,或者还有什么我遗漏的吗?

编辑:澄清一下:是否有任何命令可以在击键时改变某些东西,但如果没有任何触动就会运行?

提前感谢您的帮助!

问候

geisterfurz007

@echo off
setlocal EnableDelayedExpansion

rem Create an empty file
cd . > key.txt

rem Start a parallel process that wait for Enter key
rem and add a line to the empty file
start "" /B cmd /C "set /P = & echo line >> key.txt"

set "key="
:wait
   cls
   set "number=%random:~-4%"
   echo %number%
   echo/
   echo Press Enter key to stop the numbers...
   set /P key=< key.txt
if not defined key goto wait

echo The last number is: %number%