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 | Rate Thread | 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 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 |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
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 |
#5
|
|||
|
|||
How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
On Tue, 29 May 2018 22:17:02 +1200, Ralph Fox wrote:
A) Create one version of the batch file using CHOICE for Win 7-10 (see below), and another version using SET /P for Win XP. I can't see how SET /P is capable to get a single character input without the need to press the ENTER key. All from the keyboard, and not from file-to-input redirection. |
#6
|
|||
|
|||
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. |
#7
|
|||
|
|||
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. |
#8
|
|||
|
|||
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! |
#9
|
|||
|
|||
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. |
#10
|
|||
|
|||
How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
On Tue, 29 May 2018 18:04:03 +0700, JJ wrote:
On Tue, 29 May 2018 22:17:02 +1200, Ralph Fox wrote: A) Create one version of the batch file using CHOICE for Win 7-10 (see below), and another version using SET /P for Win XP. I can't see how SET /P is capable to get a single character input without the need to press the ENTER key. All from the keyboard, and not from file-to-input redirection. It isn't capable. The OP cross-posted to the newsgroups for Win 10, Win XP, and Win 7. * CHOICE is supported in Windows 7-10 and does not require the ENTER key. * CHOICE is *not* supported in Windows XP, so the suggested answer falls back to using SET /P on Windows XP. That way, the batch script can run on all 3 OSes which the OP cross-posted to, and does not need the ENTER key in 2 out of 3 OSes. My appologies if this was not clear and needed spelling out. -- Kind regards Ralph Those who can, do; those who can't, teach. |
#11
|
|||
|
|||
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 |
#12
|
|||
|
|||
How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
In , Ralph Fox
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? |
#13
|
|||
|
|||
How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
On Wed, 30 May 2018 07:45:54 +0000 (UTC), Bob J Jones wrote:
In , Ralph Fox 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? Yes, that makes sense. -- Kind regards Ralph |
#14
|
|||
|
|||
How do you make a batch file accept 1-char keyboard input WITHOUThaving to also press carriage return?
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:\TEMPchoice /? 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. |
#15
|
|||
|
|||
How do you make a batch file accept 1-char keyboard input WITHOUT having to also press carriage return?
On Wed, 30 May 2018 12:15:43 +0100, Java Jive
wrote: 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:\TEMPchoice /? 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. My XP VM reports the following: Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\TEMPchoice /? 'choice' is not recognized as an internal or external command, operable program or batch file. |
|
Thread Tools | |
Display Modes | Rate This Thread |
|
|