PCbanter

PCbanter (http://www.pcbanter.net/index.php)
-   General XP issues or comments (http://www.pcbanter.net/forumdisplay.php?f=18)
-   -   How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return? (http://www.pcbanter.net/showthread.php?t=1104258)

Bob J Jones May 29th 18 01:13 AM

How do you make a batch file accept 1-char 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?

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?

[email protected] May 29th 18 02:19 AM

How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
 
On Tue, 29 May 2018 00:13:59 +0000 (UTC), Bob J Jones
wrote:

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?


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 May 29th 18 08:57 AM

How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
 
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[_32_] May 29th 18 09:22 AM

How do you make a batch file accept 1-char keyboard input WITHOUThaving to also press carriage return?
 
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 "xenter" such that
the keypress carries out your desired action.

PrintScreen == "xenter"

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[_6_] May 29th 18 11:04 AM

How do you make a batch file accept 1-char keyboard input WITHOUThaving to also press carriage return?
 
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[_4_] May 29th 18 11:28 AM

How do you make a batch file accept 1-char keyboard input WITHOUThaving to also press carriage return?
 
On 29/05/2018 02:13, Bob J Jones wrote:
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?


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 May 29th 18 02:44 PM

How do you make a batch file accept 1-char keyboard input WITHOUThaving to also press carriage return?
 
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.

[email protected] May 29th 18 06:01 PM

How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
 
On Tue, 29 May 2018 04:22:19 -0400, Paul
wrote:

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 "xenter" such that
the keypress carries out your desired action.

PrintScreen == "xenter"

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


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[_32_] May 29th 18 07:01 PM

How do you make a batch file accept 1-char keyboard input WITHOUThaving to also press carriage return?
 
wrote:
On Tue, 29 May 2018 04:22:19 -0400, Paul
wrote:

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 "xenter" such that
the keypress carries out your desired action.

PrintScreen == "xenter"

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


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


My guess is, the batch file is for WinXP or later.

Paul

mike[_10_] May 29th 18 07:32 PM

How do you make a batch file accept 1-char keyboard input WITHOUThaving to also press carriage return?
 
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?

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?

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 May 29th 18 10:38 PM

How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
 
In , Java Jive
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 May 29th 18 11:59 PM

How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
 
On Tue, 29 May 2018 11:32:31 -0700, mike 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 May 30th 18 06:28 AM

How do you make a batch file accept 1-char keyboard input WITHOUThaving to also press carriage return?
 
On 2018-05-29 03:57, R.Wieser wrote:

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).


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 /
! (o o) Member:David-Suzuki-Fdn/EFF/Red+Cross/SPCA/Planetary-Society
oO-( )-Oo Funny, I don't remember being absent minded.


Ralph Fox May 30th 18 08:11 AM

How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
 
On Tue, 29 May 2018 21:38:34 +0000 (UTC), Bob J Jones wrote:

In , Java Jive
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 May 30th 18 08:31 AM

How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
 
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




All times are GMT +1. The time now is 06:32 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2006 PCbanter
Comments are property of their posters