bers
bers

Reputation: 5771

Arrow keys trigger "pause" twice in Windows batch files

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

Upvotes: 8

Views: 1422

Answers (2)

script'n'code
script'n'code

Reputation: 365

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

Upvotes: 4

Jon
Jon

Reputation: 3065

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."

Upvotes: 9

Related Questions