Home > categories > Machinery & Equipment > Press > How to register a command without pressing enter? Batch File?
Question:

How to register a command without pressing enter? Batch File?

In a batch file, I know what this will do.set/p cho=gt;if %cho%==w goto UPif %cho%==a goto LEFTif %cho%==d goto RIGHTYou press the key, hit enter, and it goes to the corresponding section in the batch file. But how do I make it, so when the user of the file presses one key, it goes to that section instantly without having to press enter?

Answer:

Something like this ECHO OFF SET Choice= SET /P Choice=Press enter to open abc.exe (and something else to quit) IF %Choice%== GOTO Start GOTO End :Start echo abc.exe about to start abc.exe :End EDIT: If you want just any key without pressing enter then this is impossible with the DOS scripting language but you could write a little exe utility who will do that for you. Here is how it looks: C:Usersholtest Press enter to open abc.exe (and something else to quit) If you press enter then we get: C:Usersholtest2 Press enter to open abc.exe (and something else to quit) abc.exe about to start 'abc.exe' is not recognized as an internal or external command, operable program or batch file. C:Usershol I have not abc.exe so there is an error message. The other way around C:Usersholtest2 Press enter to open abc.exe (and something else to quit)x gives C:Usersholtest2 Press enter to open abc.exe (and something else to quit)x C:Usershol Basically set /p ask the user to specify the value of Choice when it is just enter then it is an empty string and we can start otherwise we end. Change it around for your liking.

Share to: