My code is
Code: Select all
@echo off
echo Press any key.
bg.exe _Kbd
timeout 3 /nobreak >nul
echo %ERRORLEVEL%
pause
exit
How do I fix this?
Moderator: DosItHelp
Code: Select all
@echo off
echo Press any key.
bg.exe _Kbd
timeout 3 /nobreak >nul
echo %ERRORLEVEL%
pause
exit
Code: Select all
@echo off
echo Press any key.
bg.exe _Kbd
set key=%ERRORLEVEL%
timeout 3 /nobreak >nul
echo %key%
pause
exit
back_slash wrote: ↑05 Sep 2021 11:03@aGerman
I have. On this post (viewtopic.php?t=4094) it states there is an option called "_Kbd" to wait until a key was pressed.
@penpen
The reason I'm using _Kbd is to wait 3 seconds to give you time to press a key, The issue with Kbd is you have to press a key instead of it being optional.
Here's an example:
'Press any key in 5 seconds, if not set pressed=false.'
Notice "was" not "is"_Kbd
::If any key was pressed, returns the ascii code, else return 0.
::If the key pressed is extended, it returns the second code plus 255. Example. If you pressed the up arrow (224, 72) returns 327 (72+255).
Code: Select all
set /a "n=0"
:loop
set /a "n+=1"
bg.exe sleep 100
bg.exe _Kbd
if not errorlevel 1 if %n% lss 30 goto loop
echo %errorlevel%
You may download GetKey.exe file (and other useful auxiliary .exe programs) from Advanced Batch features via auxiliary .exe programs.Get a key from keyboard and return its value in ERRORLEVEL.
GetKey [/N]
Ascii characters are returned as positive values, extended keys as negative values.
If /N switch is given, no wait for a key: immediately return zero if no key was pressed.