目的:私は、ユーザーがただ1つの文字(任意の文字)を入力し、 "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
私は一つの単語にすべてのシンボル文字を収集するための任意の組み合わせを試してみました。誰も私が "シンボル" varの空を埋めるのを助けることができますか?
新しい文字が見つかるたびにリストを編集せずに可視の文字リストを拡張するには、これ以外のアルゴリズムはありますか?
このアプリは、ユーザーが「入力」キーを押すたびに「タイプ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