7 Replies Latest reply on May 14, 2010 9:55 AM by Flex harUI

    How do I get a key listener to listen?

    Jerry62712 Level 1

      I added a key listener to process "F1" and "F4" keys.  "F1" will bring up a help screen and "F4" will close it.  The problem is you have to click on the help screen for the "F4" key to work.  What I want to happen is from anywhere in the application you can press "F1" and from in there press "F4" to close it.

       

      I understand that Flex requires you to initially click somewhere in the application after it is opened before the "F1" will work, but I don't see why further clicks are required for the "F4" to work.

       

      I started with a [addedToStage="addedToStageHandler();"] and wonder if it should be an application item.  It looks like this:

       

      private function addedToStageHandler():void
      {
          Application.application.addEventListener(KeyboardEvent.KEY_DOWN, my_keyUpHandler);
          stage.addEventListener(KeyboardEvent.KEY_UP, my_keyUpHandler);
      }

       

      Where I added the "Application" level.  The "my_keyUpHandler" looks like this:

      private function my_keyUpHandler(event:KeyboardEvent):void
      {
          if (event.ctrlKey)
          {
              var keyCode:uint = event.keyCode;
              if (keyCode == 107 || keyCode == 187 || keyCode == 38)
                  fontSize++;
              else if (keyCode == 109 || keyCode == 189 || keyCode == 40)
                  fontSize--;
          }

       

          if (event.keyCode == Keyboard.F1) {
              helpAccess();
          }

       

          if (event.keyCode == Keyboard.F4) {
              currentState=null;
          }

       

      Help!