开发者

Arrow keys trigger "pause" twice in Windows batch files

开发者 https://www.devze.com 2023-03-26 08:38 出处:网络
try this in an otherwise empty .bat file: @echo off echo Try space and arrow-down pause echo 1 pause echo 2

try this in an otherwise empty .bat file:

@echo off
echo Try space and arrow-down
pause
echo 1
pause
echo 2
pause
echo 3
pause
echo 4
pause
echo 5
开发者_运维问答

Why does any of the arrow keys trigger two consecutive pauses, while a space or a letter only triggers one?

Thanks! bers


I suspect pause is simply a call to _getch(), which blocks until it reads a single character of input, but which has the caveat "When reading a function key or an arrow key, each function must be called twice; the first call returns 0 or 0xE0, and the second call returns the actual key code."


You can work around this problem:

PAUSE>NUL|SET /P =optional text

With thanks to http://www.dostips.com/forum/viewtopic.php?f=3&t=2726

0

精彩评论

暂无评论...
验证码 换一张
取 消