Software-OK
≡... News | ... Home | ... FAQ | Impressum | Contact | Listed at | Thank you |

  
HOME ► Faq ► FAQ - Windows cmd.exe Command-Prompt ► ««« »»»

Waiting for keyboard input Command prompt Script?


Become a sponsor!

Often you want to stop the script in the batch file and wait for the user to press Enter, or variables to process on Windows 11, 10, ... and MS Server OS!




Here is a simple script, usually the pause command is used to wait until the user has pressed a key. The calculator script is well suited to understand how to read out / use the values ​​of the user input (under Windows 11, 10, .... and MS Server)!


Content:

1.) ... Waiting for keyboard input in the batch file!
2.) ... Further tips on querying keyboard input in a batch file!

1.) Waiting for keyboard input in the batch file!

 
Here  the values ​​are queried with set /p num1= and set /p num2= and then added.

After the last  pause, you wait for any key and jump to the ":start" point!

Download: ►►►  Add-bat.bat!


@echo off
:start
 
 
echo Add-Operation
echo Please select the 2 numbers you want to add, confirm each number with ENTER
set /p num1=
set /p num2=
echo %num1%+%num2%?
pause
set /a Answer=%num1%+%num2%
echo %Answer%
pause
goto start
 
 
:e
echo. Finished!



(Image-1) Waiting for keyboard input Command prompt Script on Windows 11, 10, ...
Waiting for keyboard input Command prompt Script on Windows 11, 10, ...

-
▲ Back to the top ▲


2.) Further tips on querying keyboard input in a batch file



Keystrokes in batch files require active user interaction. You should ensure that the user understands what is expected of them and provide clear instructions. Batch files can only respond to individual keys or search for a specific key combination. Make sure you use the correct keys or key combinations to trigger the desired action.


In a batch file in Windows, you can use the pause statement to wait for keyboard input. Here is a simple example of how you can do this:



@echo off
echo Please press any key to continue...
pause > nul
echo You pressed a key!





In this example, the text “Press any key to continue…” is displayed and the batch file then waits for keyboard input. As soon as a key is pressed, the batch file execution continues and the text “You pressed a key!” appears. is displayed.

You can also use the pause statement without > nul to display the message telling the user that they need to press a key. The > nul suppresses standard output and does not display the message.

If you want to wait for a specific key or key combination, you can add additional code to validate the entered string. For example:


@echo off
echo Please press 'X' to continue... choice
/c X /n /t 15 / d X' pressed! )






In this simple example you will be asked to press the “X” key. If "X" is pressed within 15 seconds, the message "You pressed 'X'!" will appear. Otherwise, the message “You didn't press 'X'!” will be displayed. displayed.

Adapt these examples to your needs or combine the examples.

Info:

Batch files can pose potential security risks, especially if they process user input without proper validation. Make sure you carefully consider which user submissions are accepted. Processing keystrokes in batch files can be useful in simpler scenarios, but for more complex applications you may want to use more powerful scripting languages ​​or development environments.





FAQ 104: Updated on: 2 October 2023 14:40 Windows
Windows-Console

Command line arguments in the command prompt with examples!


For parameters that can be passed when the batch file is called and other variables via the set on Windows 11, 10, and MS Server OS Contents: 1.
Windows-Console

Files that are younger than the date can be deleted via the command line!


It is quite easy to delete files that are younger than a certain date via the command line under Windows 11, 10, and MS Server OS Everyone probably
Windows-Console

Delete all files except the most recent via command line, script or CMD.EXE?


It is easy to delete all files except the most recent via command line, script or CMD.EXE for Windows 11, 10, and MS Server The most popular script
Windows-Console

Ability to batch rename files in lower and upper case?


It is easy to rename files in batches using a script or command prompt in lower and / or upper case letters on Windows 11, 10, and MS Server OS Everyone
Windows-Console

Serial number of the hard disk under Windows 11, 10, ... via command prompt!


It is quite easy to find out the serial number of your hard disk under Windows 11, 10, or MS Server 2022, at a command prompt There are free hard
Windows-Console

Find out the PC serial number and manufacturer via command prompt?


Using the command prompt, it is easy to find out the PC serial number and manufacturer under Windows 11, 10, and MS Server OS Everyone has ► read out
Windows-Console

Lock the PC via the command prompt, Windows 11, 10, ...!


Locking Windows 11, 10, or MS Server 2022, 2019, is also possible via the command prompt It is not the fastest way to lock your Windows 11, 10,

»»

  My question is not there in the FAQ
Become a sponsor!
Asked questions on this answer:
Keywords: windows, 11, 10, console, waiting, keyboard, input, command, prompt, script, stop, batch, file, wait, user, press, enter, variables, process, server, Questions, Answers, Software




    

  + Freeware
  + Order on the PC
  + File management
  + Automation
  + Office Tools
  + PC testing tools
  + Decoration and fun
  + Desktop-Clocks

  + SoftwareOK Pages
  + Micro Staff
  + Freeware-1
  + Freeware-2
  + Freeware-3
  + FAQ
  + Downloads

  + Top
  + Desktop-OK
  + The Quad Explorer
  + Don't Sleep
  + Win-Scan-2-PDF
  + Quick-Text-Past
  + Print Folder Tree
  + Find Same Images
  + Experience-Index-OK
  + Font-View-OK

Become a sponsor!

  + Freeware
  + NonCompressibleFiles
  + 4ur-Windows-8-Mouse-Balls
  + 12-Ants
  + Q-Dir
  + DirPrintOK
  + FontViewOK
  + MeinPlatz
  + DesktopOK
  + ProcessKO
  + PAD-s


Home | Thanks | Contact | Link me | FAQ | Windows 2021 | Windows 10 | English-AV | Impressum | Translate | PayPal | PAD-s

 © 2023 by Nenad Hrg softwareok.de • softwareok.com • softwareok.com • softwareok.eu
0.061


► Workplace, This PC and computer, where is the difference? ◄

► Reset Internet Explorer settings in Windows 10, how to? ◄

► Delete Secure the Files and Shutdown the PC, the explanation! ◄



This website uses cookies to ensure you get the best experience on our website more Infos & Privacy Policy
....