Can't Assign Esc Key in a Batch File

January 14, 2010 at 20:09:53
Specs: Windows 7, AMD Phenom 9750 / 8GB
Hi. I just recently started looking in DOS commands when I had to many shortcuts on my desktop. So I found some simple Batch Menus and copy and edited them so I could use them to cut down the amount of shortcuts on my deskop. Here's 1 of them.

@echo off
Color 79
goto menu
:menu
ECHO.
ECHO ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
ECHO º [ DIRECTORIES ] º
ECHO ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
ECHO º 1. NBA 2k10 º
ECHO º 2. Dragon Age: Origins º
ECHO º 3. Steam º
ECHO º 4. Divinity II - Ego Draconis º
ECHO º 5. Prototype º
ECHO º 6. Close $tax Menu º
ECHO ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
ECHO.
ECHO Which Directory Would You Like To Open?
ECHO.
CHOICE /C:123456
IF ERRORLEVEL ==6 EXIT
IF ERRORLEVEL ==5 GOTO PROTOTYPEdir
IF ERRORLEVEL ==4 GOTO DIVINITYdir
IF ERRORLEVEL ==3 GOTO STEAMdir
IF ERRORLEVEL ==2 GOTO DAOdir
IF ERRORLEVEL ==1 GOTO NBA2K10dir
:NBA2K10dir
%SystemRoot%\explorer.exe "C:\Program Files (x86)\2K Sports\NBA 2K10"
cls
goto menu
:DAOdir
%SystemRoot%\explorer.exe "C:\Program Files (x86)\Dragon Age\bin_ship"
cls
goto menu
:STEAMdir
%SystemRoot%\explorer.exe "C:\Program Files (x86)\Steam"
cls
goto menu
:DIVINITYdir
%SystemRoot%\explorer.exe "C:\Program Files (x86)\Divinity2"
cls
goto menu
:PROTOTYPEdir
%SystemRoot%\explorer.exe "C:\Program Files (x86)\Activision\Prototype"
cls
goto menu
:end

This menu works great but I want the Esc key to Exit the menu instead of the #6 how do I assign the Esc key


See More: Cant Assign Esc Key in a Batch File

Report •

#1
January 14, 2010 at 22:01:15
this was kind of funky, and i'm really suprised as hell it worked at all. use EDIT (not notepad etc.) to edit your batchfile. Where it has "choice /c:xxx", go to the last "x" and do ctrl-P which allows you to insert a nonprintable char, then hit ESC key. (it will look like <- ie: backarrow) and save the batch. whatever position you put the ESC in should now be resolvable by you batchscript using errorlevel as usual.
keep me posted, I'm curious

Report •

#2
January 14, 2010 at 22:09:26
You probably don't.

But you may want to change:

CHOICE /C;123456

to either:

CHOICE /C123456
CHOICE /C:123456

so your results are not skewed.


=====================================
Helping others achieve escape felicity

M2


Report •

#3
January 14, 2010 at 22:13:22
I'm also curious.

If the works you get the Mr.Goodwrench Award for the month.


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
January 14, 2010 at 23:27:41
where did you see choice /c; (?)
(i hope your eyes not as bad as mine)
forget goodwrench.. if it works, will you buy me a beer?
(not to worry, nothing works coming from this corner! LL)

Report •

#5
January 14, 2010 at 23:36:03
lline 19 of posted code.

Yep, you're good for a beer.


=====================================
Helping others achieve escape felicity

M2


Report •

#6
January 14, 2010 at 23:39:01
thanks man, i'll let you off easy (this time): miller lite
ok line 19 (of code):
CHOICE /C:123456

?


Report •

#7
January 14, 2010 at 23:46:34
sheesh

I better give this up for Lent.

It's a colon.


=====================================
Helping others achieve escape felicity

M2


Report •

#8
January 14, 2010 at 23:59:55
LL!
just don't give up beer!

Report •

#9
January 15, 2010 at 00:20:14
ok i was looking around to find out what you mean by using EDIT. i tried
c:\>edit
edit c:\filepath

neither works. theirs no edit.com

btw im using Windows 7
heres a link to see the menu if you want
the menu above.
http://www.fotothing.com/photos/e18...
the menu to open the games themselves.
http://www.fotothing.com/photos/53f...


Report •

#10
January 15, 2010 at 01:18:02
man, i can't believe that! MS strikes again. funky solution becomes funkier. (not your fault... I tend to assume systems have older apps same as i always have on hand like EDIT)
It could be done with DEBUG (does your system have that?
type DEBUG and if it looks serious, ( a dash prompt) type Q.
if you have DEBUG. and if your program is exactly as presented here (exactly):
make this file, call it (f/e) d.d with this content:
e2b7 1b
w

copy your script to f/e xxxx.bat, then
debug xxxx.bat <d.d

that replaces "6" with ESC, but if and only if it is exactly
in the place in the batch file. If you know how to use DEBUG, then go for it, that's WAY better.

This seems like a real "overkill" situation, you might not want to mess, but if you do, you might learn some things (especially how MS pulls the rug!)

it were me, i would want a copy of EDIT, it beats hell out of most other apps for simple text work. I'm sure you could goog it up and download. it's EDIT.COM, about 70Kbytes on my XP.
there might be easier ways to do this, hopefully there are and forum conribs might chip in if knowledgable.
keep me posted, i'll help much as i can...


Report •

#11
January 15, 2010 at 01:34:26
I think someone unfamiliar with debug will want the d.d to have:

e2b7 1b
w
q
[blank line]


=====================================
Helping others achieve escape felicity

M2


Report •

#12
January 15, 2010 at 01:48:40
lol i had a felling that they had changed some things. like edit, debug is no longer a valid command or at least they've changed the way they get used or changed the name of the commands themselves.

I'll keep looking just not quite as hard. Spent alot of hours looking and reading. My head is hurting from all the info i've gained, so a couple asprin and it will have been worth it- :?)


Report •

#13
January 15, 2010 at 01:49:23
thanks! saved again from me own petard...

I'm thinking of a binary line editor... just one line... using debug - script exports line to file, debug puts in the nasties, writes it back to 1-line file, script re-imports it.
i don'no, nah, too much troubulations.
there's so much really slick sh_t out there it boggles my mind...


Report •

#14
January 15, 2010 at 01:50:11
Edit: Where did those three posts come from ;)

Hi nbrane,

I think it gets even worse:

"C:\Program Files (x86)\"

I think this is a pretty good indicator that this is actually for win 7 x64. Good chance of there not being debug and perhaps not even being able to run edit.com without quite a bit of effort.

Further more the version of choice may not accept esc at all. I have choice.com from win98 which will accept esc as outlined above and choice.exe from one of ms' toolkits that it won't work with.


Batch Variable how to


Report •

#15
January 15, 2010 at 01:59:18
@shhm: (my last post was @to M2)
wow... i mean, wow... i never would have DREAMED...
well, that's why they have "oldies" servers, or we can just recreate the wheel using visbasic or vbscript etc. Well, you get the gist, implant the ESC (=1B) into the batch and you're good to go. QBASIC can even do that! (ah! hand-to-head-smack! NO! qbasic is even further out than debug or edit!)
the menus and stuff looked pretty good... I didn't run it but just looking at the code...
it's just one friggin byte for cryin-out-loud... keep me posted

Report •

#16
January 15, 2010 at 02:11:45
@judago, thanks for input and enlightenment, my posts kind of went around yours, just now saw yours. things i take for granted keep getting sucked out from under my feet! I keep forgetting stuff "moves on", (or "moves" somewhere, away from my knowledge). OK, waxing philosophical here...
I think of cars: the new ones are really slick and do lots of cool stuff, but when they break, joe-bloe like me is f_ked. The old ones, IF you can get parts and have basic knowledge, you can get them to at least get you down the road. I like new stuff but i really like old stuff since i'm old and simple.
I need to learn-up on more new stuff...but i'll always have old junk laying around.

Report •

#17
January 15, 2010 at 02:15:49
I patched in the 1b but choice won't accept esc as a keypress. Just sits there waiting for 1 thru 5.

In the interest of not getting wrapped around the axel, I would:

choice /c:123456q

and use q to quit.


=====================================
Helping others achieve escape felicity

M2


Report •

#18
January 15, 2010 at 02:16:53
Edit: Beaten again!

The char itself can be copied from the forum and pasted into notepad(test ok for me from the preview):



The only problem is that the trick likely won't work in the reimplemented versions of choice and the original versions of choice likely won't run under x64/


Batch Variable how to


Report •

#19
January 15, 2010 at 02:43:06
yeah, it (ESC) pasted just fine, so i guess you nailed the whole issue: "which choice" and "which op.systm and which 'choice' works in it". Mine was very very old, real simple version (5K, .com), just happened to work in XP. 64's are a whole new league...

Report •

#20
January 15, 2010 at 02:50:27
I' pretty sure if you wanted to get around it bad enough you could. @Everyone ty for trying and i think i may have found something for every1 in the future. @nbrane & @ Judago specifically ty b/c i wouldnt have found if it wasnt for your Esc key inputs. when i put in to the batch file it tells me valid characters are as follows. a-z, A-Z, 0-9 and ASCII values 128-254 so the escape key is not recognized. If you got a sure fire way to get around this feel free to post though.

Report •

#21
January 15, 2010 at 03:14:32
@nbrane

I only just noticed your post about only just noticing about my post ;)

I agree with you new stuff is cool but the user is so isolated from it if only for it's complexity. The phrase "they don't build 'em like they used to" comes to mind, next to nothing is user serviceable so few bother to even try to understand how thing work. "It's broken, throw it away......."


@Jshmalchak

The only sure fire way is to use another programming language or third party utility.


Batch Variable how to


Report •

#22
January 16, 2010 at 03:58:54
Interesting thread, I need to scroll through it, but it's very interesting to add special keys to be allowed to CHOICE

I just tried to run the solution as posted in Response nr.1, but it didn't really work.

Anyway, would it work with F-keys as well ? Enter key ?

-- edit:
Well, it seems to work, but only for CHOICE.COM, not for CHOICE.EXE

ex.

C:\Temp>CHOICE.com /C:12345←
[1,2,3,4,5,←]?←

C:\Temp>CHOICE.exe /C:12345←
[1,2,3,4,5,←]?

The second and last comand would not do anything when pressing ESC


Report •

#23
January 16, 2010 at 11:56:24
probply not for the F-keys, (or alt-keys) because they are a two-key sequence with leading byte 00. it might take some
control-keys though, not tried it.
a small .com "commandlet":
mov ah,7
int 21
mov ah,4c
int 21
can capture any key including
zero (ctrl-shift-@) into the %errorlevel%, but then you have to code a translator in order to build a string:
set asctable=...0123456789...ABCDE...abcde...~
:aa
keycapt
set xx=%errorlevel%
if %xx%=13 goto :displayword
(edit: bungled this next line, fixed it!)
set word=!word!!asctable:~%xx%,1!
goto :aa
:displayword
echo.!word!

but this use of errorlevel is only supported by xp and above.
(lower systems can test for errorlevel but not assign it to vars)


Report •

#24
January 17, 2010 at 04:51:21
F-keys wont work indeed, since they are not ASCII matched. The rest of your reply, is a bit too technical ... even for me.

Report •

Ask Question