If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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 ption1 if '%option%'=='2' goto ption2 if '%option%'=='3' goto ption3 if '%option%'=='x' goto :exit if '%option%'=='h' goto :help echo Insert 1, 2, x or h timeout 3 goto start ption1 route delete 0.0.0.0 %defgw% echo Default gateway "%defgw%" removed timeout 3 goto start ption2 route add 0.0.0.0 mask 0.0.0.0 %defgw% echo Defaulte gateway "%defgw%" restored timeout 3 goto start ption3 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? |
Ads |
#2
|
|||
|
|||
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 ption1 if '%option%'=='2' goto ption2 if '%option%'=='3' goto ption3 if '%option%'=='x' goto :exit if '%option%'=='h' goto :help echo Insert 1, 2, x or h timeout 3 goto start ption1 route delete 0.0.0.0 %defgw% echo Default gateway "%defgw%" removed timeout 3 goto start ption2 route add 0.0.0.0 mask 0.0.0.0 %defgw% echo Defaulte gateway "%defgw%" restored timeout 3 goto start ption3 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. |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
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 |
#5
|
|||
|
|||
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 |
#6
|
|||
|
|||
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 ption1 if '%option%'=='2' goto ption2 if '%option%'=='3' goto ption3 if '%option%'=='x' goto :exit if '%option%'=='h' goto :help echo Insert 1, 2, x or h timeout 3 goto start ption1 route delete 0.0.0.0 %defgw% echo Default gateway "%defgw%" removed timeout 3 goto start ption2 route add 0.0.0.0 mask 0.0.0.0 %defgw% echo Defaulte gateway "%defgw%" restored timeout 3 goto start ption3 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 |
#7
|
|||
|
|||
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. |
#8
|
|||
|
|||
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 |
#10
|
|||
|
|||
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 ption1 if '%option%'=='2' goto ption2 if '%option%'=='3' goto ption3 if '%option%'=='x' goto :exit if '%option%'=='h' goto :help echo Insert 1, 2, x or h timeout 3 goto start ption1 route delete 0.0.0.0 %defgw% echo Default gateway "%defgw%" removed timeout 3 goto start ption2 route add 0.0.0.0 mask 0.0.0.0 %defgw% echo Defaulte gateway "%defgw%" restored timeout 3 goto start ption3 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. |
#11
|
|||
|
|||
How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
In news
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! |
#12
|
|||
|
|||
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. |
#13
|
|||
|
|||
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) Memberavid-Suzuki-Fdn/EFF/Red+Cross/SPCA/Planetary-Society oO-( )-Oo Funny, I don't remember being absent minded. |
#14
|
|||
|
|||
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 news 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 |
#15
|
|||
|
|||
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 |
|
Thread Tools | |
Display Modes | |
|
|