objective: i want user to type just a single character (any character) and then the script immediately responds without additional keystroke of "enter" key. if user type "enter" key without any character previously entered, the script would not respond.
i am stuck with this code:
@Echo Off
SET Alnum=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
:: ordinary symbol string would not work!
:: it must be escaped, but i don't know how.
SET Symbol=
SETLOCAL EnableExtensions EnableDelayedExpansion
CALL :CharInput "Type one char: "
ECHO Your input was: "!RetVal!"
ECHO(
CALL :CharInput "one more char: "
ECHO Your input was: "!RetVal!"
ECHO(
CALL :CharInput "still need more: "
ECHO Your input was: "!RetVal!"
ECHO(
GOTO :eof
:: @param1 %~1 message to print
:: @return RetVal the single character entered by user
:CharInput
IF "" == "!VisibleChars!" (
CALL :CharacterizedWord "%Alnum%%Symbol%"
SET VisibleChars=!RetVal!
)
SET /P "=%~1" < Nul
SET Found=false
FOR /F "skip=1" %%# IN ('REPLACE "%~f0" . /U /W') DO SET "CHR=%%#"
SET /P "=!CHR!" <Nul
FOR %%a in (!VisibleChars!) DO (
IF "%%a" == "!CHR!" (
SET Found=true
)
)
:: needs work around to make the script print only 1 message
:: each time the user presses the "enter" key
:: without any visible characters previously entered
IF "false" == "!Found!" (
ECHO(
GOTO :CharInput
) ELSE (
SET "RetVal=!CHR!"
ECHO(
)
GOTO :eof
:: @param1 %~1 the word being characterized
:: @return RetVal the string contains words each of single character
:CharacterizedWord
SET Word=%~1
SET tempstr=%~1
SET count=0
:CharacterizedWordLoop
IF DEFINED tempstr (
SET tempstr=%tempstr:~1%
SET /a count+=1
SET /a pos=%count%-1
SET RetVal=!RetVal! !Word:~%pos%,1!
GOTO :CharacterizedWordLoop
)
GOTO :eof
I have tried any combination to collect all symbol chars into a single word. Can anyone help me to fill the emptiness of "Symbol" var?
Is there any better algorithm other than this to expand the visible character list without editing the the list each time i find new character?
This app is still print "Type one char: " message each time user presses the "enter" key. Can anyone fix this?