2

I've been working on a batch file to perform several tasks and usually ask the user to enter 1, or 2 to choose between options.

This time, I'd like to use a different approach, keystrokes so that the user can select a choice by pressing the UP or DOWN arrow keys. This is where I want to include the UP/DOWN strokes for the user.

    echo 1. go to the main menu? 
    echo 2. Go to the next backup?
    echo.
    set INPUT=
    set /P INPUT=Type input: %=%

    If "%INPUT%"=="1" goto start1 
    If "%INPUT%"=="2" goto start2

The above portion of code works for me. Now instead of using "1" or "2" I'd like to use {DOWN} or {UP}

https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx

I don't seem to make this work out in my batch by trying these lines:

    If /I "%INPUT%"=="{UP}" goto start1 
    If /I "%INPUT%"=="{DOWN}" goto start2

Here:

batch file that detects keystrokes. how?

This article adresses the topic of choosing between keystrokes awsd and I've tested it, it works perfect only in my case I need for the arrow keys to perform the task.

Community
  • 1
  • 1
  • 2
    `SendKeys` is a Windows Script Host method, therefore you must use it in a js or vbs file – phuclv Oct 17 '16 at 02:02
  • 2
    Possible duplicate of [batch file that detects keystrokes. how?](http://stackoverflow.com/questions/4340191/batch-file-that-detects-keystrokes-how) – NineBerry Oct 17 '16 at 02:07
  • 2
    Cannot be done in pure batch. Either code the whole script in VBscript or give this a try. http://www.dostips.com/forum/viewtopic.php?t=6936 – Squashman Oct 17 '16 at 02:10
  • Something's telling me that learning CMD is not really effective for the purposes of my tests? @Squashman powershell and other languages seem to be more useful – Pedro Velez Oct 17 '16 at 02:14
  • 2
    @PedroVelez, every language has its strengths and weaknesses. There are some things that batch files do very well at, even better then Powershell or Vbscript. – Squashman Oct 17 '16 at 02:19
  • @PedroVelez When using choice, Capital H will also capture the Up Arrow key and capital P will also capture the Down Arrow key. It is mentioned in the other question I linked to. – NineBerry Oct 17 '16 at 02:27
  • (but it seems this only worked in DOS and doesn't work any longer in modern Windows versions) – NineBerry Oct 17 '16 at 02:40

0 Answers0