Choice is very limited, so you need another solution.
One way is to use an own function which uses xcopy
for the key input.
:GetKey
set "key="
for /F "usebackq delims=" %%L in (`xcopy /L /w "%~f0" "%~f0" 2^>NUL`) do (
if not defined key set "key=%%L"
)
set "key=%key:~-1%"
exit /b
The xcopy /L /W tries to copy the batch-file to itself.
The /W is the important option, it requires a key press before the copy process starts, and the key is shown.
The copy itself fails always, as the file can't copy to itself.
Therefor the error stream is redirected to NUL with 2>NUL
.
The FOR /F captures the complete line with the keystroke.
And the set "key=%key:~-1%"
picks only the last character from the line.
The good thing is that xcopy accepts and shows nearly all keys (F1 .. F12 and some other still fails), even Backspace and Enter can be detected this way.