Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 486
bers Avatar asked Aug 05 '11 14:08

bers


People also ask

How do you pause 10 seconds in a batch file?

PAUSE. The most obvious way to pause a batch file is of course the PAUSE command. This will stop execution of the batch file until someone presses "any key". Well, almost any key: Ctrl, Shift, NumLock etc.

What is @echo off?

When echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt again, type echo on. To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type: Copy. @echo off.

What is %% A in batch?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


1 Answers

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

like image 200
Jon Avatar answered Sep 27 '22 18:09

Jon