3 Replies Latest reply on Jan 30, 2011 12:11 AM by Flex harUI

    Flex kbd event help

    billiam407

      Using the example I found at http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf64a29-7fdb.html, I modified my Flex app to listen for keyboard shortcuts being pressed.  It works but only after the user clicks on a blank spot on the web page.  Why?  This is for accessibility and if I make my blind users click using a mouse, it defeats the purpose... Is there a fix for this so that the keystrokes are detected without clicking on the page or am I doing something wrong?

       

      Here is my code:

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:Application

       

       

      xmlns:fx="http://ns.adobe.com/mxml/2009"

      xmlns:s="

      library://ns.adobe.com/flex/spark"

      xmlns:mx="

      library://ns.adobe.com/flex/mx"

      creationComplete="init()"

      minWidth="

      955" minHeight="600">

       

       

      <fx:Declarations>

       

       

      <!-- Place non-visual elements (e.g., services, value objects) here -->

       

       

      </fx:Declarations>

       

       

      <fx:Script source="BGBasicPlay.as" >

       

      </fx:Script>

       

      <fx:Script>

      <![CDATA[

       

       

      import mx.core.FlexGlobals;

       

      protected function init():void {

      FlexGlobals.topLevelApplication.addEventListener(KeyboardEvent.KEY_DOWN,keysPressed);

      }

       

      // has to set focus then click to work!!!

       

       

      protected function keysPressed(evt:KeyboardEvent):void {

      txtKeys.text = evt.keyCode +

      "/" + evt.charCode;

       

      var nKeyPressed:int = evt.keyCode;

       

      if (nKeyPressed == 80 && evt.shiftKey == true)

      {

      PlaySong2();

      }

       

      else {

       

      if (nKeyPressed == 80 && evt.shiftKey == false)

      {

      PlaySong();

      }

      }

      }

      ]]>

       

      </fx:Script>

       

      <s:Button x="250" y="105" label="Play Song" id="btnPlay" />

       

      <s:TextInput x="224" y="63" id="txtKeys"/>

      </s:Application>

        • 1. Re: Flex kbd event help
          Flex harUI Adobe Employee

          See past threads on browser focus

          • 2. Re: Flex kbd event help
            billiam407 Level 1

            After wading through over 100 posts, most were either unanswered or had general replies such as yours with no real useful information on how to do this.

             

            The closest answer I found was this:

            "This is a known bug of Flash Player/Mozilla browsers - SWF does not receive focus at start-up.
            I am not aware about any suitable workaround available. The closest workaround is to place a button and allow user to click on it which will give SWF a focus.

            PS It works in IE without any problem. Good old MS "

             

            That answer was posted in 2008.  It is now 2011 and you would think that this would have a fix by now... especially with all of the pressure for accessibility.  IE 8 apparently now has this problem as well.

             

            So, instead of sending me on a wild goose chase, it would really have been more helpful to have received an actual answer from you.

             

             

             

             

             

            • 3. Re: Flex kbd event help
              Flex harUI Adobe Employee

              I'm not the expert in this area, and my impression is that the capabilities

              of the browsers is changing daily.  Therefore, I don't have a definitive

              answer for you.  I think I've written this summary before, but basically my

              understanding is this:

               

              The browsers tend to not give the flash player focus.  There is javascript

              you can run on IE and maybe a few other browsers to assign focus to the

              player.  I have seen conflicting reports on whether it works on recent

              versions of FireFox, it didn't work on older ones.