Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Make batch react to buttons  (Read 10619 times)

0 Members and 1 Guest are viewing this topic.

Sky Ninja

    Topic Starter


    Rookie

  • *headdesk*
    Make batch react to buttons
    « on: October 10, 2008, 08:23:16 PM »
    I need to make a batch file react to button pushes, but most people who get my file won't have the choice command available. I don't want them to have to go through installing it, so is there a way other than choice /c:?

    Carbon Dudeoxide

    • Global Moderator

    • Mastermind
    • Thanked: 169
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Experience: Guru
    • OS: Mac OS
    Re: Make batch react to buttons
    « Reply #1 on: October 10, 2008, 08:35:12 PM »
    Nope, you cannot make a button like on the Internet.

    Sky Ninja

      Topic Starter


      Rookie

    • *headdesk*
      Re: Make batch react to buttons
      « Reply #2 on: October 10, 2008, 08:49:51 PM »
       ???
      What I meant is a button on the keyboard. I need an alternative to choice /c:*whatever*.
      I know you can't do things such as clickable buttons. That's only available through .com or .exe. Edit.com for example.

      Carbon Dudeoxide

      • Global Moderator

      • Mastermind
      • Thanked: 169
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Experience: Guru
      • OS: Mac OS
      Re: Make batch react to buttons
      « Reply #3 on: October 10, 2008, 08:52:30 PM »
      Oh sorry, do you mean Keyboard presses?  :D

      Sky Ninja

        Topic Starter


        Rookie

      • *headdesk*
        Re: Make batch react to buttons
        « Reply #4 on: October 10, 2008, 08:53:41 PM »
        Yep.

        Carbon Dudeoxide

        • Global Moderator

        • Mastermind
        • Thanked: 169
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Experience: Guru
        • OS: Mac OS
        Re: Make batch react to buttons
        « Reply #5 on: October 10, 2008, 09:33:39 PM »
        I think there might be a way, but you will have to wait for our Batch Gurus to assist. ;)

        Dias de verano

        • Guest
        Re: Make batch react to buttons
        « Reply #6 on: October 11, 2008, 02:49:09 AM »
        Code: [Select]
        @echo off

        REM Create getkey.com
        echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.com
        echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.com
        echo l/QnKE@HB61H.>>getkey.com

        REM Run getkey.com which...
        REM ...waits for a keypress
        getkey.com

        REM ASCII value of key is contained in %errorlevel%
        echo %errorlevel%

        ALAN_BR



          Hopeful

          Thanked: 5
          • Computer: Specs
          • Experience: Experienced
          • OS: Windows 7
          Re: Make batch react to buttons
          « Reply #7 on: October 11, 2008, 02:50:55 AM »
          Hi

          Immediately below the "Logout" button you will find a Search box

          If you search for "choice" you get more hits than I care to list.

          The first Hit takes you to "http://www.computerhope.com/choicehl.htm"
          This links to "http://www.computerhope.com/sethlp.htm", which should give more than enough help.

          If you want further help, or want to see examples of how to do it, then Hit 2, or any one of more than 50 other hits, should do the job.

          Regards
          Alan

          Jacob



            Hopeful

            Thanked: 1
            • Experience: Expert
            • OS: Windows XP
            Re: Make batch react to buttons
            « Reply #8 on: October 11, 2008, 02:59:59 AM »
            Just getting all of the key numbers, watch this space.
            « Last Edit: October 11, 2008, 03:17:59 AM by Jacob »

            Dias de verano

            • Guest
            Re: Make batch react to buttons
            « Reply #9 on: October 11, 2008, 03:12:24 AM »
            The pause would help :P

            I guess if you run the batch by double clicking it in Windows Explorer, yes, it would help by stopping the command window abruptly closing. I am used to trialling new batch files by having a command window open and typing the batch name at the prompt, to avoid exactly that problem.

            Also, it strikes me that it might be handy to know the actual character of the key which has been pressed, so I whipped up a simple vbscript to return that

            Code: [Select]
            @echo off
            echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.com
            echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.com
            echo l/QnKE@HB61H.>>getkey.com
            echo Wscript.echo Chr^(WScript.Arguments^(0^)^)>CharFromASCII.vbs

            Echo Please press a key

            getkey.com
            set ascii=%errorlevel%
            for /f "delims==" %%C in ('cscript //nologo CharFromASCII.vbs %ascii%') do set char=%%C
            del getkey.com
            del CharFromASCII.vbs

            echo You pressed this key: %char%

            REM Complete with PAUSE at the end...
            REM Thanks to Jacob.

            PAUSE
            « Last Edit: October 11, 2008, 04:29:54 AM by Dias de verano »

            Jacob



              Hopeful

              Thanked: 1
              • Experience: Expert
              • OS: Windows XP
              Re: Make batch react to buttons
              « Reply #10 on: October 11, 2008, 03:18:52 AM »
              The pause would help :P

              I guess if you run the batch by double clicking it in Windows Explorer, yes, it would help by stopping the command window abruptly closing. I am used to trialling new batch files by having a command window open and typing the batch name at the prompt, to avoid exactly that problem.

              Also, it strikes me that it might be handy to know the actual character of the key which has been pressed, so I whipped up a simple vbscript to return that

              Code: [Select]
              @echo off
              echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.com
              echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.com
              echo l/QnKE@HB61H.>>getkey.com
              echo Wscript.echo Chr^(WScript.Arguments^(0^)^)>CharFromASCII.vbs

              Echo Please press a key

              getkey.com&for /f "delims==" %%C in ('cscript //nologo CharFromASCII.vbs %errorlevel%') do set char=%%C
              del getkey.com&del CharFromASCII.vbs

              echo You pressed this key: %char%

              REM Complete with PAUSE at the end...
              REM Thanks to Jacob.

              PAUSE

              Just as I was trying to do it the hard way:

              Dias de verano

              • Guest
              Re: Make batch react to buttons
              « Reply #11 on: October 11, 2008, 03:25:24 AM »
              Yes, my first thought was to do it the long way, of testing for every errorlevel possible, then I remembered how many keys there are on a keyboard, and I thought that nobody will want to add several hundred lines to their batch file.

              Jacob



                Hopeful

                Thanked: 1
                • Experience: Expert
                • OS: Windows XP
                Re: Make batch react to buttons
                « Reply #12 on: October 11, 2008, 03:26:33 AM »
                This is just every letter in case anybody wants it:
                Code: [Select]
                @echo off

                REM Create getkey.com
                echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.com
                echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.com
                echo l/QnKE@HB61H.>>getkey.com

                REM Run getkey.com which...
                REM ...waits for a keypress
                :run
                getkey.com

                REM ASCII value of key is contained in %errorlevel%
                If %errorlevel%==97 (
                echo A
                )
                If %errorlevel%==98 (
                echo B
                )
                If %errorlevel%==99 (
                echo C
                )
                If %errorlevel%==100 (
                echo D
                )
                If %errorlevel%==101 (
                echo E
                )
                If %errorlevel%==102 (
                echo F
                )
                If %errorlevel%==103 (
                echo G
                )
                If %errorlevel%==104 (
                echo H
                )
                If %errorlevel%==105 (
                echo I
                )
                If %errorlevel%==106 (
                echo J
                )
                If %errorlevel%==107 (
                echo K
                )
                If %errorlevel%==108 (
                echo L
                )
                If %errorlevel%==109 (
                echo M
                )
                If %errorlevel%==110 (
                echo N
                )
                If %errorlevel%==111 (
                echo O
                )
                If %errorlevel%==112 (
                echo P
                )
                If %errorlevel%==113 (
                echo Q
                )
                If %errorlevel%==114 (
                echo R
                )
                If %errorlevel%==115 (
                echo S
                )
                If %errorlevel%==116 (
                echo T
                )
                If %errorlevel%==117 (
                echo U
                )
                If %errorlevel%==118 (
                echo V
                )
                If %errorlevel%==119 (
                echo W
                )
                If %errorlevel%==120 (
                echo X
                )
                If %errorlevel%==121 (
                echo Y
                )
                If %errorlevel%==122 (
                echo Z
                )
                goto run
                PAUSE >nul

                Dias de verano

                • Guest
                Re: Make batch react to buttons
                « Reply #13 on: October 11, 2008, 03:31:08 AM »
                1. Your code only works for lowercase letters of the alphabet 'a' to 'z'.

                2. But you show uppercase letters to the user. ASCII 97 is 'a' not 'A'. The keypress program gives a different code if a key is shifted or if Caps Lock is operative.

                3. By using this format

                if test (
                   do this
                )

                Rather than this

                if test do this

                You are adding 2 unnecessary lines for each simple IF test




                Jacob



                  Hopeful

                  Thanked: 1
                  • Experience: Expert
                  • OS: Windows XP
                  Re: Make batch react to buttons
                  « Reply #14 on: October 11, 2008, 03:40:34 AM »
                  1. Your code only works for lowercase letters of the alphabet 'a' to 'z'.

                  2. But you show uppercase letters to the user. ASCII 97 is 'a' not 'A'. The keypress program gives a different code if a key is shifted or if Caps Lock is operative.

                  3. By using this format

                  if test (
                     do this
                  )

                  Rather than this

                  if test do this

                  You are adding 2 unnecessary lines for each simple IF test





                  Thanks for the unseen problem fix.
                   ;)

                  Code: [Select]
                  @echo off

                  REM Create getkey.com
                  echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.com
                  echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.com
                  echo l/QnKE@HB61H.>>getkey.com

                  REM Run getkey.com which...
                  REM ...waits for a keypress
                  :run
                  getkey.com
                  set key=%errorlevel%
                  REM ASCII value of key is contained in %Key%
                  If %Key%==97 echo a [%Key%]
                  If %Key%==98 echo b [%Key%]
                  If %Key%==99 echo c [%Key%]
                  If %Key%==100 echo d [%Key%]
                  If %Key%==101 echo e [%Key%]
                  If %Key%==102 echo f [%Key%]
                  If %Key%==103 echo g [%Key%]
                  If %Key%==104 echo h [%Key%]
                  If %Key%==105 echo i [%Key%]
                  If %Key%==106 echo j [%Key%]
                  If %Key%==107 echo k [%Key%]
                  If %Key%==108 echo l [%Key%]
                  If %Key%==109 echo m [%Key%]
                  If %Key%==110 echo n [%Key%]
                  If %Key%==111 echo o [%Key%]
                  If %Key%==112 echo p [%Key%]
                  If %Key%==113 echo q [%Key%]
                  If %Key%==114 echo r [%Key%]
                  If %Key%==115 echo s [%Key%]
                  If %Key%==116 echo t [%Key%]
                  If %Key%==117 echo u [%Key%]
                  If %Key%==118 echo v [%Key%]
                  If %Key%==119 echo w [%Key%]
                  If %Key%==120 echo x [%Key%]
                  If %Key%==121 echo y [%Key%]
                  If %Key%==122 echo z [%Key%]
                  ::----------------------------------------------------------
                  If %Key%==65 echo A [%Key%]
                  If %Key%==66 echo B [%Key%]
                  If %Key%==67 echo C [%Key%]
                  If %Key%==68 echo D [%Key%]
                  If %Key%==69 echo E [%Key%]
                  If %Key%==70 echo F [%Key%]
                  If %Key%==71 echo G [%Key%]
                  If %Key%==72 echo H [%Key%]
                  If %Key%==73 echo I [%Key%]
                  If %Key%==74 echo J [%Key%]
                  If %Key%==75 echo K [%Key%]
                  If %Key%==76 echo L [%Key%]
                  If %Key%==77 echo M [%Key%]
                  If %Key%==78 echo N [%Key%]
                  If %Key%==79 echo O [%Key%]
                  If %Key%==80 echo P [%Key%]
                  If %Key%==81 echo Q [%Key%]
                  If %Key%==82 echo R [%Key%]
                  If %Key%==83 echo S [%Key%]
                  If %Key%==84 echo T [%Key%]
                  If %Key%==85 echo U [%Key%]
                  If %Key%==86 echo V [%Key%]
                  If %Key%==87 echo W [%Key%]
                  If %Key%==88 echo X [%Key%]
                  If %Key%==89 echo Y [%Key%]
                  If %Key%==90 echo Z [%Key%]
                  ::----------------------------------------------------------
                  If %Key%==32 echo SpaceBar [%Key%]

                  ::ECHO [%KEY%]


                  goto run
                  PAUSE >nul