Page 1 of 1

[Resolved] Alternative xcopy function to Choice - Carriage return as accepted character possible?

Posted: 18 Sep 2019 00:44
by koko
I came across this superb script by by aGerman which is a functional replacement to the choice command using xcopy behind the scenes, executing the conditional errorlevel commands only if the character input matches a predefined list (like choice /n). Was ideal as I was looking for something that didn't beep on invalid inputs as choice does.
aGerman wrote:
02 Nov 2015 13:36
That function may help...
What I was wondering is whether the Enter key/carriage return could be defined as a valid input character along with the other valid 'choices' characters, as I was hoping for a way to define a default command to execute if the prompt is 'skipped' by pressing Enter. The other non-choice-like set /p prompts in my script I made to behave in this manner to quickly apply defaults (in those prompts I have it conditionally apply commands if nothing was entered).

Wasn't sure of forum etiquette of necro'ing topics so decided to make a new topic, hope no one minds.

Re: Alternative xcopy function to Choice - Carriage return as accepted character possible?

Posted: 18 Sep 2019 10:02
by aGerman
What I was wondering is whether the Enter key/carriage return could be defined as a valid input
Basically you can. The subroutine contains the line

Code: Select all

if defined c (
which checks if you pressed Enter without any other input before (which is the case if c is not defined at this position). You can't define it in the map variable though. And of course it needs a separate handling.

Steffen

Re: Alternative xcopy function to Choice - Carriage return as accepted character possible?

Posted: 18 Sep 2019 10:59
by dbenham
You might also want to look at :getKey and :getAnyKey that use REPLACE instead of XCOPY.

Both forms can return a value representing a carriage return, and have an option to specify valid characters, including Carriage Return.


Dave Benham

Re: Alternative xcopy function to Choice - Carriage return as accepted character possible?

Posted: 18 Sep 2019 17:27
by koko
aGerman wrote:
18 Sep 2019 10:02
Basically you can. The subroutine contains the line

Code: Select all

if defined c (
which checks if you pressed Enter without any other input before (which is the case if c is not defined at this position). You can't define it in the map variable though. And of course it needs a separate handling.
dbenham wrote:
18 Sep 2019 10:59
You might also want to look at :getKey and :getAnyKey that use REPLACE instead of XCOPY.

Both forms can return a value representing a carriage return, and have an option to specify valid characters, including Carriage Return.
Thank you both. Will look into it.