5 Replies Latest reply on Jan 5, 2009 12:23 PM by Ned Murphy

    [flash5] how to trigger all numpad keys?

    Level 7
      Hi all,
      I'm not familiar with flash actionscript, but I need to update an old
      flash5 application that used buttons and the attached code to trigger
      events:

      on (keyPress "<right>") {
      some action here;
      }

      The example above triggers the right arrow key.

      I would like to trigger all numpad keys but If I use something like:

      on (keyPress "7") {
      some action here;
      }

      I can't use the key 7 on the keyboard in input fields.
      When I type 7 in an input field the keypress is ignored.

      Is there a way to force the keypress to use the specific key 7 on the
      numpad and not the 7 key from the keyboard?
      I need to modify it for flash5 and I'm not able to rewrite the whole thing
      to work with CS3 and actionscript 3.0.

      Any help is really appreciated.

      tony
        • 1. [flash5] how to trigger all numpad keys?
          Ned Murphy Adobe Community Professional & MVP
          Here's some AS2 code that you might find useful. It will trace the key code so that you can figure out what the key codes are for the ones you want to use, and you can see how it is set up to take action for the 7 key on the keypad. The results will differ depending on the Numeric Lock status of the keypad... in my case, with the lock off, 7 apparently has no code.
          • 2. Re: [flash5] how to trigger all numpad keys?
            Level 7
            > var keyListener:Object = new Object();
            > Key.addListener(keyListener);
            >
            > keyListener.onKeyUp = function(){
            > trace(Key.getCode());
            > if(Key.getCode() == 97){ // key 7 on enabled num-pad
            > trace("clicked 7 on pad");
            > }
            > }

            Thanks, NedWebs,

            but how can I add it to an existing buttom actionscript?
            If I add it to a button, the debugger says that these instructions must be
            inserted inside an 'on' handler.

            Any suggestion will be very appreciated.

            Thanks again. ;).

            Tony
            • 3. [flash5] how to trigger all numpad keys?
              Ned Murphy Adobe Community Professional & MVP
              Just add this code to a main timeline actions layer separately from any buttons--it is dedicated to the keyboard. You can still add code separately for the same actions to whatever on-stage buttons you want to have duplicate the functionality.
              • 4. Re: [flash5] how to trigger all numpad keys?
                Level 7
                > Just add this code to a main timeline actions layer separately from any buttons--it is dedicated to the keypad. You can still add code for the same actions to whatever on-stage buttons you want.

                Hi Ned,
                the problem here is that the keypress action should control the button
                content (rotate the button itself).
                I added the "on (keypress)" action to the button and when I press the
                related key on the keyboard, the actions are triggered on the same buttons.
                I have at least 100 buttons on the stage and every button behaves the same
                way: I select a button and then I rotate it using the keyboard.
                How can I obtain this using your code on the main timeline?

                Thanks again and again ;).

                tony
                • 5. Re: [flash5] how to trigger all numpad keys?
                  Ned Murphy Adobe Community Professional & MVP
                  I don't know how to apply keycodes to a keyPress event beyond the standard ones, so the best I can offer is...

                  Give each button an instance name and use the code I showed to apply whatever _rotation or other action you need for the buttons.