목표 : 나는 하나의 문자 (모든 문자)를 입력하고 "enter"키를 추가로 누르지 않아도 즉시 응답합니다. 사용자가 이전에 입력 한 문자없이 "enter"키를 입력하면 스크립트가 응답하지 않습니다.보이는 단일 문자를 입력 한 다음 즉시 배치로 처리하는 방법 CMD
는이 코드에 붙어입니다 :
나는 모든 기호를 수집하기 위해 조합을 시도@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
가 하나의 단어로가 문자. "Symbol"var의 공허함을 채울 수있는 사람이 있습니까?
새로운 문자를 찾을 때마다 목록을 편집하지 않고 보이는 문자 목록을 확장하는 다른 알고리즘이 있습니까?
이 앱은 사용자가 "enter"키를 누를 때마다 여전히 "유형 1 문자 :"메시지를 인쇄합니다. 누구든지이 문제를 해결할 수 있습니까?
시험해주세요. https://stackoverflow.com/questions/13166100/how-can-i-return-a-single-character-from-the-console-in-a-batch-script-without-p CHOICE – Ctznkane525
@ 존 케인 : 상징은 어때요? 네이티브 선택은 기호를 지원하지 않습니다. –
에는 선택시 특수 문자를 사용하는 방법에 대한 정보가 있습니다. 기술적으로 지원되지 않지만 해결 방법은 https://stackoverflow.com/questions/41456194/how-to-use-special-characters-in-choice-command-batch-file – Ctznkane525