12 Replies Latest reply on Nov 10, 2010 7:53 AM by suku511

    Reg: keyboard event handling

    suku511

      Hi All,

       

      I am trying to capture F11 key down, but I couldn't. I could able to capture other keys but my requirement is that I need to capture F11 key, Because in my application we are using Pod based Layout, So if one pod is maximized and when F11 key is pressed, the pods in the application is going to the default state(all to normal state , even the maximized pod also).

       

      Could any one Guide me through, Handling the F11 key capture is right approach for my solution or Is there any better way to solve my problem.

       

      Thanks,

      Sukumar.

        • 1. Re: Reg: keyboard event handling
          dpark1113

          Did you try keycode 122?

          • 2. Re: Reg: keyboard event handling
            rvollmar

            Could you describe what's not working?  Writing a method to handle the application's keyDown event, and checking to see if the event's keyCode matches the code for F11 (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/ui/Keyboard.html) should work.

            • 3. Re: Reg: keyboard event handling
              suku511 Level 1

              Its not going to that handler/listner to check the keycode

               

              in init function I added the following line,

               

              addEventListener(KeyboardEvent.KEY_DOWN, onF11Down);

               

               

              I tried with keycode == 122 and also with

               

              switch (e.keyCode){

              case Keyboard.F11:

              trace('Hi')

              }

               

              this condition but nothing is happening so I kept breakpoint and checked, then I noticed that when I enter any other keys Its going to onF11Down funtion.

               

              but when I press F11 key or any function keys Its not going to that function. So Is It possible to do? If so how can I listen for F11 keydown??

               

              Thanks,

              Sukumar.

              • 4. Re: Reg: keyboard event handling
                suku511 Level 1

                yeah It should work according to the API. I did the same way  Wrote a method to handle the application's keyDown event, and checking to see if the event's keyCode matches the code for F11. but its not going to the method when F11 is pressed , Heres the sample snippet of code which I tried seperately from my application creating a new application even It didnt work....

                 

                 

                 

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

                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"

                backgroundColor="#FFFFFF"

                applicationComplete="registerGlobalKeyHandler()">

                 

                <mx:Script>

                <![CDATA[

                public function registerGlobalKeyHandler() :void

                {

                stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);

                }

                 

                public function handleKeyDown(event:KeyboardEvent) :void

                {

                display.text = "Key was pressed: " + event.keyCode;

                }

                ]]>

                </mx:Script>

                 

                <mx:Label id="display"

                  text="Click anywhere in the application and then press some keys." />

                 

                </mx:Application>

                 

                 

                I could able c the keycodes for all other keys but when pressing function keys Its not even going to the handleKeyDown function

                 

                Is there any way to listen to the function when F11 is pressed??

                 

                Thanks,

                Sukumar

                • 5. Re: Reg: keyboard event handling
                  dpark1113 Level 1

                  I think it is browser based, it works on Chrome but not on IE.  In IE, if you hit F11 several times really fast, it detects it on my computer(Windows Vista).

                   

                  My guess is IE uses F11 and I believe it has priority over web app.

                  • 6. Re: Reg: keyboard event handling
                    rvollmar Level 1

                    Hello,

                     

                    The code below worked for me.  When using my MacBook Pro's keyboard, it didn't work, but with a keyboard plugged in, it worked when I pressed Ctrl + F11.

                     

                    <?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" minWidth="955" minHeight="600" keyUp="doKeyDown(event)" keyDown="doKeyDown(event)">

                     

                        <fx:Script>
                            <![CDATA[
                                private function doKeyDown(e:KeyboardEvent):void{
                                    if(e.keyCode == flash.ui.Keyboard.F11){
                                        btn1.label = "got F11";
                                    }else{
                                        btn1.label = "didn't";
                                    }
                                }
                            ]]>
                        </fx:Script>
                       
                        <s:Button width="100%" id="btn1" label="waiting" />

                     

                    </s:Application>

                    • 7. Re: Reg: keyboard event handling
                      suku511 Level 1

                      Hm Exactly I agree with you , So Is there any workaround ? Just to make sure whether its a bug or we can achieve from flex itself

                      • 8. Re: Reg: keyboard event handling
                        dpark1113 Level 1

                        Just found out that in IE, F11 is full screen.  I think you should be able to disable F11 in html using javascript.  But I don't know how that is going to affect in Flex if you disable F11 within html browser.  Interesting to know. 

                        • 9. Re: Reg: keyboard event handling
                          suku511 Level 1

                          Thanks for your quick response. I am Using windows and the browser is IE, Just to make sure Whether its possible/can be done with IE or not? or Are there any ways to achieve this??

                          • 10. Re: Reg: keyboard event handling
                            suku511 Level 1

                            Thanks for your Quick Responses.

                             

                            Than disabling F11 in html using Javascript, I guess launching the application in F11 is better. Interesting to know if it is not the better way?

                             

                            So first thing,

                             

                            If we cant achieve this, the only way we have is,

                             

                            Either to disable F11 or to Launch the application in F11 using Java script.

                             

                            So, Just to make sure whether its a bug or we can't achieve from flex?

                             

                            thanks,

                            Sukumar

                            • 11. Re: Reg: keyboard event handling
                              dpark1113 Level 1

                              I don't think this is a bug.  It's just how it is.  Either your client needs to use different browser or disable Fullscreen from IE.  Some says the javascript doesn't even work because IE just ignores it.  

                              1 person found this helpful
                              • 12. Re: Reg: keyboard event handling
                                suku511 Level 1

                                Thanks for reply. I am trying with launching my application in F11.