Discussion:
using the enter key in the choice command
(too old to reply)
Jim Bauer
2003-11-19 06:01:11 UTC
Permalink
Hey all!
Was just wondering if and/or how I could get choice.com to recognize
the enter or carriage return key as an available key in the "/c" flag.
Thanks for any and all help!
Cheers, Jim
Joe Batch
2003-11-19 08:31:10 UTC
Permalink
Post by Jim Bauer
Was just wondering if and/or how I could get choice.com to recognize
the enter or carriage return key as an available key in the "/c" flag.
The usual method requires ansi.sys is loaded via config.sys
and involves re-mapping the enter key to a different value
and restoring it afterwards.

:: entchoic.bat
@echo off
set esc=
echo @prompt set esc=%%esc%%$e$_>%temp%.\$setesc1.bat
%comspec%/e:4096/c %temp%.\$setesc1.bat>%temp%.\$setesc2.bat
call %temp%.\$setesc2.bat
del %temp%.\$setesc?.bat
choice.com /c%esc%/n " Press [Enter] to continue%esc%[13;27p"
echo %esc%[13;13p
set esc=

I might recommend putting the following line in before choice.
echo %esc%[10;13p

This is so [Ctrl]+[Enter] will function as an alternate [Enter]
key if the batch is broken out of with [Ctrl]+[C] or
[Ctrl]+[Break] while choice is waiting for a response. A good
safety feature for autoexec.bat in case you terminate any batch
that alters the value for [Enter], and could potentially leave
you with a nonfunctional [Enter] key.
Joe Batch
2003-11-19 08:43:36 UTC
Permalink
Post by Jim Bauer
Was just wondering if and/or how I could get choice.com to recognize
the enter or carriage return key as an available key in the "/c" flag.
The usual method requires ansi.sys is loaded via config.sys
and involves re-mapping the enter key to a different value
and restoring it afterwards.

:: entchoic.bat
@echo off
set esc=
echo @prompt set esc=%%esc%%$e$_>%temp%.\$setesc1.bat
%comspec%/e:4096/c %temp%.\$setesc1.bat>%temp%.\$setesc2.bat
call %temp%.\$setesc2.bat
del %temp%.\$setesc?.bat
choice.com /c%esc%/n " Press [Enter] to continue%esc%[13;27p"
echo %esc%[13;13p%esc%[1A
set esc=

I might recommend putting the following line in before choice.
echo %esc%[10;13p

This is so [Ctrl]+[Enter] will function as an alternate [Enter]
key if the batch is broken out of with [Ctrl]+[C] or
[Ctrl]+[Break] while choice is waiting for a response. A good
safety feature for autoexec.bat in case you terminate any batch
that alters the value for [Enter], and could potentially leave
you with a nonfunctional [Enter] key.

BTW, the %esc%[1A eliminates the exta output line from the
echo command. Technique also useful for eliminating the extra
line after ctty con, ie.

@echo off
ctty nul
batch code here
ctty con
%esc%[2A
Ted Davis
2003-11-19 14:18:14 UTC
Permalink
Post by Jim Bauer
Hey all!
Was just wondering if and/or how I could get choice.com to recognize
the enter or carriage return key as an available key in the "/c" flag.
Thanks for any and all help!
Cheers, Jim
Basically, you can't.

One of the things you can do is to use a utility (not CHOICE) that
reports raw key codes or character numbers. A trivial example that
can be created on the fly by a batch file is the GETCH utility at
<http://gearbox.maem.umr.edu/~batch/debug.scripts.1.html>. I say
"trivial" because it probably can't be done in fewer than the eight
bytes that program uses. The program uses the BIOS function that
waits for a key press, then returns the character number and scan code
- the scan code is discarded and the program terminates with the
character code as its exit code (ERRORLEVEL). The DEBUG script is

a
XOR AX,AX
INT 16
MOV AH,4C
INT 21

rcx
8
ngetch.com
w

The actual code is the four lines in upper case.



T.E.D. (***@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.
Joe Batch
2003-11-20 10:55:40 UTC
Permalink
Post by Ted Davis
Post by Jim Bauer
Was just wondering if and/or how I could get choice.com to recognize
the enter or carriage return key as an available key in the "/c" flag.
Basically, you can't.
Yes, you can. See my posted solution in this thread.
Post by Ted Davis
One of the things you can do is to use a utility (not CHOICE) that
reports raw key codes or character numbers.
...it probably can't be done in fewer than the eight
bytes that program uses.
Perhaps, but there is no benefit in counting them.
Post by Ted Davis
The program uses the BIOS function that
waits for a key press, then returns the character number and scan code
- the scan code is discarded and the program terminates with the
character code as its exit code (ERRORLEVEL). The DEBUG script is
a
XOR AX,AX
INT 16
MOV AH,4C
INT 21
rcx
8
ngetch.com
w
There should be a quit command above; placing a 'q' on
the next line after 'w' will prevent debug from hanging.

Here is another debug approach.

:: codescan.bat (makes codescan.com)
@ECHO OFF
ECHO A 100 >%temp%.\codescan.dbg
ECHO MOV AH,0>>%temp%.\codescan.dbg
ECHO INT 16>>%temp%.\codescan.dbg
ECHO MOV AL,AH>>%temp%.\codescan.dbg
ECHO MOV AH,4C>>%temp%.\codescan.dbg
ECHO INT 21>>%temp%.\codescan.dbg
ECHO.>>%temp%.\codescan.dbg
ECHO RCX>>%temp%.\codescan.dbg
ECHO A>>%temp%.\codescan.dbg
ECHO N %temp%.\codescan.com>>%temp%.\codescan.dbg
ECHO W>>%temp%.\codescan.dbg
ECHO Q>>%temp%.\codescan.dbg
DEBUG.EXE <%temp%.\codescan.dbg >nul


The errorlevel set by the above two programs is different.

Getch.com sets errorlevel based on the ASCII decimal value,
and codescan.com sets errorlevel based on the Scan decimal
value.

As seen below, the [5] key on the main keyboard (line 1) is
slightly different than the [5] key on the numeric keypad
(line 2).

ASCII Extended Scan
Key Dec Hex Char Dec Hex Char Dec Hex
-----------------------------------------------------------
5 53 35 5 6 06
5 53 35 5 76 4C

Here is another program by Paul Bartlett which is very similar
to the first program, it sets errorlevel based on the ASCII
decimal value and outputs the actual key value to the screen.

N KEYGET.COM
A 100
MOV AH,01 ;Request Keyboard Input with Echo function 01
INT 21 ;from MSDOS
MOV AH,4C ;Request program end and return exit code (= key code)
INT 21 ;from DOS service routines

RCX
8
W
Q

Loading...