3 Replies Latest reply on Jul 6, 2009 1:40 AM by EgorKDie

    Function keys

    Tatofly

      There are a way to capture all function keys (F1..F24) without browser intercepting?

        • 1. Re: Function keys
          rgadiparthi

          try this- http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postI d=304

           

          <?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>
          • 2. Re: Function keys
            *Prashant Shelke* Level 4

            on creationComplete event of your mainApp.mxml or any outer container call


            public function init():void
            {
                try
                {
                    addEventListener( KeyboardEvent.KEY_DOWN, onKeyDown );
                }
                catch(error : Error)
                {
                    Alert.show("error : " + error.getStackTrace());
                }
            }


            private function onKeyDown( event:KeyboardEvent ):void
            {
                if (event.keyCode == Keyboard.F12)// Keyboard.F1, & so on...
                {
                    Next code ......
                }
            }

            • 3. Re: Function keys
              EgorKDie Level 2

              Yes, though the guys above have missed out the "without the browser intercepting" part.

               

              You need to capture the keypress in javascript, and stop it from propogating through to the browser, otherwise the F5 key is going to reload your page.