Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?

122 views
Skip to first unread message

Bob J Jones

unread,
May 28, 2018, 8:14:05 PM5/28/18
to
How do you make a batch file accept single-character keyboard input
WITHOUT having to also press carriage return?

This generic DOS network kill script works great to kill the network,
for example, whenever you install programs that you don't want to
phone home.
https://www.liquidvpn.com/vpn-kill-switches/

All the DOS script does is disable and re-enable the router gateway
(192.168.1.1) in the routing table.

But it's a pain to always have to hit carriage return after pressing
1, 2, or 3. It would be nice if just pressing the 1, 2, or 3
(or "d" for disable and "e" for enable) worked in the script without
the script needing the user to also press the carriage return.

FILE: LiquidVPN-Kill-Switch.bat
LOCATION: https://www.liquidvpn.com/billing/dl.php?type=d&id=49

Do you know DOS batch scripts well enough to tell us how to eliminate
the need to press the carriage return after pressing the
(1) to disable the gateway, the
(2) to re-enable the gateway, or
(3) to set the gateway?

Here is a snippet of that code.
set defgw=192.168.0.1
echo Your routers gateway is probably "%defgw%"
echo -if nothing appears or its incorrect, add it manually (Press '3')
echo.
echo USAGE:
echo.
echo -Press "1" to Enable Kill Switch (IP "%defgw%")
echo -Press "2" to Disable Kill Switch (IP "%defgw%")
echo -Press "3" to manually set default gateway if its not detected above.
echo -Press "h" for Kill Switch Help
echo -Press "x" to exit Kill Switch.
echo.
set /p option=Your option:
if '%option%'=='1' goto :option1
if '%option%'=='2' goto :option2
if '%option%'=='3' goto :option3
if '%option%'=='x' goto :exit
if '%option%'=='h' goto :help
echo Insert 1, 2, x or h
timeout 3
goto start
:option1
route delete 0.0.0.0 %defgw%
echo Default gateway "%defgw%" removed
timeout 3
goto start
:option2
route add 0.0.0.0 mask 0.0.0.0 %defgw%
echo Defaulte gateway "%defgw%" restored
timeout 3
goto start
:option3
echo
set /p defgw=your gw IP (e.g. 192.168.0.1):
goto start
:help
cls

How do you make a batch file accept single-character keyboard input
WITHOUT having to also press carriage return?

gfre...@aol.com

unread,
May 28, 2018, 9:19:37 PM5/28/18
to
If you are really using DOS, you load ANSI.SYS and use the PROMPT
command to redefine keystrokes to command lines but I am not sure how
you do that after W/98.

R.Wieser

unread,
May 29, 2018, 3:58:12 AM5/29/18
to
Directed at the OP (but I do not see his post here ...)

>>How do you make a batch file accept single-character keyboard input
>>WITHOUT having to also press carriage return?

Find yourself a program named CHOICE.COM (DOS 6.22). It returns an error
level result for keys you specify (and, IIRC, even allows for a "default
choice" timeout).

Regards,
Rudy Wieser


Paul

unread,
May 29, 2018, 4:22:21 AM5/29/18
to
Bob J Jones wrote:
> How do you make a batch file accept single-character keyboard input
> WITHOUT having to also press carriage return?

The options here look pretty miserable.
Still, you could take a browse through it.
There are some helper routines listed
near the end.

http://www.robvanderwoude.com/userinput.php

*******

The only thing I can suggest, is binding some key
to generate a string, such as "x<enter>" such that
the keypress carries out your desired action.

PrintScreen ==> "x<enter>"

And no, I have nothing like that loaded on the
computer here, and I don't know if solving that
problem is any easier.

I'm really surprised they made it that difficult.

HTH,
Paul

Andy Burns

unread,
May 29, 2018, 6:04:57 AM5/29/18
to
Bob J Jones wrote:

> How do you make a batch file accept single-character keyboard input
> WITHOUT having to also press carriage return?

<https://helloacm.com/lost-era-microsoft-dos-com-assembly-8-byte-program-getkey>

Fokke Nauta

unread,
May 29, 2018, 6:28:59 AM5/29/18
to
Why not use the JPSoft TCC/LE command processor? Is offers many more
options than the DOS/Windows command processor, although it's very
similar and you can use the same commands (and much more). It's very
simple in a batch file to ask for an input character without the Enter key.
This processor is free. You can write batch files with the .btm extension.
If you wanna give it a try, I can give you help. I have been using it
for years.

Fokke

Java Jive

unread,
May 29, 2018, 9:44:47 AM5/29/18
to
On 29/05/2018 01:13, Bob J Jones wrote:
>
> How do you make a batch file accept single-character keyboard input
> WITHOUT having to also press carriage return?

PAUSE echoes "Press a key to continue ..." and waits for the user to
press any single key.

However, if you want the user to make a choice, then, surprise,
surprise, use the CHOICE command, as in the following W9x example (the
CHOICE command is still available in W7, but its parameters may alter
somewhat between versions of Windows):

CLS
ECHO %Title%
ECHO.
ECHO 0 Quit
ECHO 1 Partition Hard Disk
ECHO 2 Format Hard Disk
ECHO 3 Configure PC Or Netcard
ECHO 4 Image PC To Or From Server
ECHO 5 Exit To DOS
ECHO.
CHOICE /C:012345 /N "Please choose [012345]: "
ECHO.
IF ERRORLEVEL 1 SET Choice=ExitDos
IF ERRORLEVEL 2 SET Choice=StdFDisk
IF ERRORLEVEL 3 SET Choice=Format
IF ERRORLEVEL 4 SET Choice=Setup
IF ERRORLEVEL 5 SET Choice=Image
IF ERRORLEVEL 6 SET Choice=ExitDos
GOTO %Choice%

See also CHOICE /? for help.

gfre...@aol.com

unread,
May 29, 2018, 1:01:41 PM5/29/18
to
On Tue, 29 May 2018 04:22:19 -0400, Paul <nos...@needed.invalid>
wrote:
Did we ever figure out if he was really running DOS or just running at
the command prompt in windows.
If it is real DOS and you have ASNI.SYS loaded you can do stuff like
this (My old DOS 6.3 AUTOEXEC.BAT)


BREAK ON
ECHO ON
PROMPT $e[1;33;44m Sets screen color
PROMPT $E[96;"*.*" Adds *.* to the current command and hits enter
prompt $e[58;59p These two swap the colon and semi colon
prompt $e[59;58p
prompt $e[0;62;"f4";13p Runs "F4" bat
prompt $e[0;64;"wprf";13p Runs "WPRF.EXE"
prompt $e[0;65;"f7";13p Runs "F7 BAT"
prompt $e[0;66;"dir /w/p";13p Does a DIR/W/P
prompt $e[0;67;"exit";13p Enters "exit" into dBase
prompt $e[0;68;"return";13p Enters "return" into dBase
prompt $e[0;94;"| more";13p Adds |more to current command

prompt $t$_$d$_$p$g
CLS

Paul

unread,
May 29, 2018, 2:01:54 PM5/29/18
to
My guess is, the batch file is for WinXP or later.

Paul

mike

unread,
May 29, 2018, 2:32:36 PM5/29/18
to
Don't have a direct answer to your question, but some things to think about.
I had a problem trying to select the audio stream in VLC.
I needed to send a single character. Didn't have a keyboard.
I wrote a short VB program that waits two seconds, then sends "s"
to the active window. I couldn't figger out how to select the
VLC window in the program because the title bar changes with every video.
The two seconds let me double click the shortcut, then click
the vlc window to accept the "s".

For your purpose, there's another option.
There's a program called FastIPchanger.
It lets you change your network settings with a couple of clicks.
I have tab setting for DHCP.
Second tab setting uses a fixed IP address that happens to be the
same one that DHCP would get per address reservation.
It sets the default gateway to 0.0.0.0.
That disconnects me from the WEB, but keeps access to the local network.

Bob J Jones

unread,
May 29, 2018, 5:38:39 PM5/29/18
to
In <news:pejlgb$1g2r$1...@gioia.aioe.org>, Java Jive <ja...@evij.com.invalid>
wrote:

> See also CHOICE /? for help.

Thanks.
This CHOICE command seems to be the way to go.

I'm no coder, and I don't have the time I had this weekend, but I'll try it
out when I can and report back if I'm successful.

That way everyone benefits from your kind and helpful expert suggestion!

Char Jackson

unread,
May 29, 2018, 6:59:05 PM5/29/18
to
On Tue, 29 May 2018 11:32:31 -0700, mike <ham...@netzero.net> wrote:

>On 5/28/2018 5:13 PM, Bob J Jones wrote:
>
>> How do you make a batch file accept single-character keyboard input
>> WITHOUT having to also press carriage return?
>
>For your purpose, there's another option.
>There's a program called FastIPchanger.
>It lets you change your network settings with a couple of clicks.
>I have tab setting for DHCP.
>Second tab setting uses a fixed IP address that happens to be the
>same one that DHCP would get per address reservation.
>It sets the default gateway to 0.0.0.0.
>That disconnects me from the WEB, but keeps access to the local network.

0.0.0.0 isn't a valid gateway, so it's equivalent to simply removing the
gateway, which is what his script already does. I'd prefer removing the
entry rather than changing it to something that's invalid, but the
result is the same either way.

B00ze

unread,
May 30, 2018, 1:28:19 AM5/30/18
to
I use CHOICE.EXE, is it not included in all versions of Windows?

--a------ 2010-11-20 23:24 36864 C:\Windows\System32\choice.exe

Regards,

--
! _\|/_ Sylvain / B00...@hotmail.com
! (o o) Member:David-Suzuki-Fdn/EFF/Red+Cross/SPCA/Planetary-Society
oO-( )-Oo Funny, I don't remember being absent minded.

Ralph Fox

unread,
May 30, 2018, 3:11:51 AM5/30/18
to
On Tue, 29 May 2018 21:38:34 +0000 (UTC), Bob J Jones wrote:

> In <news:pejlgb$1g2r$1...@gioia.aioe.org>, Java Jive <ja...@evij.com.invalid>
> wrote:
>
>> See also CHOICE /? for help.
>
> Thanks.
> This CHOICE command seems to be the way to go.


You cross-posted to the XP newsgroup, so I would guess that you also want
the batch script to run in XP.

Be aware that CHOICE is not supported in Windows XP.


> I'm no coder, and I don't have the time I had this weekend, but I'll try it
> out when I can and report back if I'm successful.
>
> That way everyone benefits from your kind and helpful expert suggestion!


--
Kind regards
Ralph

R.Wieser

unread,
May 30, 2018, 3:32:10 AM5/30/18
to
B00ze,

> I use CHOICE.EXE, is it not included in all versions of Windows?

Nope. At least, its not on my machine (COM or EXE)

Regards,
Rudy Wieser


Bob J Jones

unread,
May 30, 2018, 3:45:58 AM5/30/18
to
In <news:rdjsgddbmeuq7oqur...@4ax.com>, Ralph Fox
<-rf-nz-@-.invalid> wrote:

> You cross-posted to the XP newsgroup, so I would guess that you also want
> the batch script to run in XP.
>
> Be aware that CHOICE is not supported in Windows XP.

A simple switch can solve that, don't you think?
The default would be set to WINXP compatible.
If the user changes that switch to anything other than WINXP, then the
CHOIC code runs.

Something like this Pseudocode:

set defos=WINXP
if defos not WINXP then run CHOICE commands
else run default SET /P commands

Does that make sense to you as a general game plan?

Ralph Fox

unread,
May 30, 2018, 3:58:12 AM5/30/18
to
Yes, that makes sense.

--
Kind regards
Ralph

Java Jive

unread,
May 30, 2018, 7:15:56 AM5/30/18
to
On 30/05/2018 08:11, Ralph Fox wrote:
>
> Be aware that CHOICE is not supported in Windows XP.

Nonsense, as in ...

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\TEMP>choice /?
CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]

/C[:]choices Specifies allowable keys. Default is YN
/N Do not display choices and ? at end of prompt string.
/S Treat choice keys as case sensitive.
/T[:]c,nn Default choice to c after nn seconds
text Prompt string to display

ERRORLEVEL is set to offset of key user presses in choices.


gfre...@aol.com

unread,
May 30, 2018, 7:29:15 AM5/30/18
to
On Wed, 30 May 2018 12:15:43 +0100, Java Jive <ja...@evij.com.invalid>
wrote:
I tried it on my XP and I get the message that CHOICE does not exist
but if I run the DOS 7 version it works so I guess you could just add
CHOICE to your windows32 directory.

http://gfretwell.com/ftp/CHOICE.COM

Char Jackson

unread,
May 30, 2018, 11:15:54 AM5/30/18
to
On Wed, 30 May 2018 12:15:43 +0100, Java Jive <ja...@evij.com.invalid>
wrote:

My XP VM reports the following:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\TEMP>choice /?
'choice' is not recognized as an internal or external command,
operable program or batch file.

Java Jive

unread,
May 30, 2018, 1:09:14 PM5/30/18
to
You're right.

My build was originally a W2k build on a P4 desktop which was reimaged
onto a laptop and upgraded to XP, so at the time of my previous post, I
made a point of searching the Windows directory for extra files that
might be giving the functionality, but in fact CHOICE.EXE is in the W2k
Resource Kit folder under Program Files, which is on my path. I suspect
that similarly it would be available from the XP Resource Kit, but what
bloody arseholes they are, removing something as *useful* as that!

Apologies for increasing the level of confusion.

Frank Slootweg

unread,
May 30, 2018, 1:14:52 PM5/30/18
to
Hmmm!? This page is somewhat ambiguous, but says "Windows XP and
earlier syntax" (Generally the ComputerHope 'DOS' pages are quite
accurate.):

<https://www.computerhope.com/choicehl.htm>

[Too much trouble to fetch my dormant XP machine, but if really needed,
I can get it, fire it up and try.]

gfre...@aol.com

unread,
May 30, 2018, 4:36:32 PM5/30/18
to
On Wed, 30 May 2018 18:09:02 +0100, Java Jive <ja...@evij.com.invalid>
The DOS 7 version I linked seems to work.
MS went out of their way to kill DOS in XP, to the point of actually
saying it was not there but most DOS tools still work fine, as do most
DOS programs. The only time you get in trouble, from what I have seen,
is when they try to use extended memory or direct disk access. They
still seem OK in DOSBOX tho. I am running my dBase IV apps just fine.
Most of the simpler DOS programs just load and go seemlessly.

Sjouke Burry

unread,
May 30, 2018, 8:11:33 PM5/30/18
to
???????????????????????????????????????????????????????????
my XP PRO sp3:
C:\01-sjouke\test>choice /?
choice wordt niet herkend als een interne
of externe opdracht, programma of batchbestand.

C:\01-sjouke\test>
Translated:NOT RECOGNIZED!!!!!

In dos 6.22 it does work.

B00ze

unread,
May 31, 2018, 12:52:54 AM5/31/18
to
Strange. I had a look at who owns Choice.EXE on my Win7pro and it is
Trusted Installer, and on top of that it's a hardlink, so I'm not the
one who put it there. I also had a look at the Win2k and WinXp resource
kits and it's not there, so it doesn't come from the kits. Which version
of Windows do you have?

Regards,

--
! _\|/_ Sylvain / B00...@hotmail.com
! (o o) Member:David-Suzuki-Fdn/EFF/Red+Cross/SPCA/Planetary-Society
oO-( )-Oo "Intel Inside" is a government warning requied by law.

R.Wieser

unread,
May 31, 2018, 2:37:15 AM5/31/18
to
B00ze,

> Which version of Windows do you have?

XP ofcourse (this is the newsgroup for it after all :-) ) service pack 3
(XPsp3).

Regards,
Rudy Wieser


B00ze

unread,
Jun 1, 2018, 12:32:57 AM6/1/18
to
On 2018-05-31 02:37, R.Wieser <add...@not.available> wrote:

> B00ze,
>
>> Which version of Windows do you have?
>
> XP ofcourse (this is the newsgroup for it after all :-) ) service pack 3
> (XPsp3).

Ah yes of course ;-) Unfortunately, I removed the drives from my Xp box
two weeks ago and do not plan on making it bootable again, so I can't
check if I had Choice on mine. Trust Microsoft to remove something in Xp
and put it back in Win7 (and then likely remove it again in Win10.) I
use Choice on WinPE bootdisks (I have to copy it from System32;
Microsoft doesn't copy it when it builds the boot WIM file) and in a few
other places, it works very well. I wouldn't be surprised if Choice in
Win7 refused to work on Xp, DOS programs did that a lot (I've had to use
SETVER a few times.)

Regards,

--
! _\|/_ Sylvain / B00...@hotmail.com
! (o o) Member:David-Suzuki-Fdn/EFF/Red+Cross/SPCA/Planetary-Society
oO-( )-Oo "Crayons take you more places than starships." -Guinan

MikeS

unread,
Nov 17, 2018, 5:14:37 PM11/17/18
to
On 29/05/2018 02:19, gfre...@aol.com wrote:
> On Tue, 29 May 2018 00:13:59 +0000 (UTC), Bob J Jones
> <bobj...@startMail.com> wrote:
>
>> How do you make a batch file accept single-character keyboard input
>> WITHOUT having to also press carriage return?
>>
>> How do you make a batch file accept single-character keyboard input
>> WITHOUT having to also press carriage return?
>
> If you are really using DOS, you load ANSI.SYS and use the PROMPT
> command to redefine keystrokes to command lines but I am not sure how
> you do that after W/98.
>
If you can find a copy the real MSDOS CHOICE command will still work in
a cmd window. But not with 64 bit Windows 10 as it dates back to 16 bit
days.

gfre...@aol.com

unread,
Nov 17, 2018, 7:35:54 PM11/17/18
to
I have a copy of CHOICE.COM from a PCDOS 7.1 disk if anyone wants to
play with it.
0 new messages