8 Replies Latest reply on Aug 3, 2009 9:54 AM by Flex harUI

    Flex 4 does not dispatch keyboard events for ENTER key.

    MikisM87

      Hello everyone. I think I have a strange problem with Flex 4 Beta (4.0.0.8909). My application has had event listener for keyUp event for a month now and suddenly (two days ago) I've noticed that keyUp event is not dispatched for ENTER (ALT also) key. Anyone know why? By the way, I've tried this with keyDown event, also 4.0.0.8847 version of SDK - still the same: no keyboard events for ENTER (and ALT) key.

      Here is the sample application that has got this issue:

       

      <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/halo"
         minWidth="640" minHeight="480"
         keyUp="application1_keyUpHandler (event)">

       

         <fx:Script>
            <![CDATA[
               import mx.controls.Alert;
              
               protected function application1_keyUpHandler (event: KeyboardEvent):void
               {
                  Alert.show ("Key up: " + event.keyCode);
               }
            ]]>
         </fx:Script>
        
         <s:layout>
            <s:BasicLayout/>
         </s:layout>
        
         <s:TextArea verticalCenter="0" horizontalCenter="0" width="200"/>
        
      </s:Application>

       

      If you run this application and try typing anything in a TextArea you will get alerts with key codes. However, if you press ENTER (or ALT), you will get no alert.

       

      I'm pretty sure the code above is right so that means there is a bug in latest nightly builds of SDK (i would swhitch to an older build if i knew which one does not have this bug).

       

      Any ideas?

        • 1. Re: Flex 4 does not dispatch keyboard events for ENTER key.
          Peter deHaan Level 4

          I'm not surprised by the Alt key. I assume the browser is hijacking that one.

           

          But can you please file a bug about the Spark TextArea not dispatching the Enter key event? It works as expected on a Halo TextArea.

           

          Peter

          • 2. Re: Flex 4 does not dispatch keyboard events for ENTER key.
            David_F57 Level 5

            This has always been an issue with flex, until your swf has focus it won't accept the keyboard events, I always placed a click event on my apps that created the the keylistener and set focus to my first textinput component and that worked.

             

            David.

            • 3. Re: Flex 4 does not dispatch keyboard events for ENTER key.
              Flex harUI Adobe Employee

              That's true, but in this case, I think the text editing code is eating ENTER key in order to prevent parents from seeing it and acting on it (like a submit button).  We'll see if we can find a way around that.

               

              You can get the ENTER key now by listening in capture phase.

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              • 4. Re: Flex 4 does not dispatch keyboard events for ENTER key.
                David_F57 Level 5

                Flex harUI wrote:

                 

                That's true, but in this case, I think the text editing code is eating ENTER key in order to prevent parents from seeing it and acting on it (like a submit button).  We'll see if we can find a way around that.

                 

                You can get the ENTER key now by listening in capture phase.

                 

                Alex Harui

                Flex SDK Developer

                Adobe Systems Inc.

                Blog: http://blogs.adobe.com/aharui

                 

                The enter key isn't being disposed of by textedit, the attached example code works without error if you a- remove the alert box and b-set the focus to your text area on initialisation. I agree that pressing the enter key then calling a dialog box will result in the enter key being "gobbled up" as  the enter key is overridden by the dialog box code.

                 

                I think the first suggestion should be to anyone don't use dialogboxes for testing code. If for some reason debugging isn't desirable instead of a trace statement a simple label  can be used as a 'fake' trace.

                 

                David

                 

                Message was edited by: David_F57: I worded this wrong, imho there is no need for a work around, the textarea component works as it should. When intercepting 'system' keycodes there is a need to consider the effect of the intercept and code appropriately to that end.

                1 person found this helpful
                • 5. Re: Flex 4 does not dispatch keyboard events for ENTER key.
                  MikisM87 Level 1

                  To Peter deHaan (Adobe): I can confirm the code with Halo TextInput works with ENTER key as expected while with Spark TextArea AND TextInput it does not. So I think I'll file a bug about this.

                   

                  To Flex harUI: Thanks for a suggestion using capturing phase instead of bubbling: works perfect.

                   

                  To David_F57: I tried using label solution instead of alert and setting the focus to the text area - it didn't help. And I agree that for the TextArea ENTER key might be used for special purpose (like newline) but more importantly the code does not work with TextInput either. So I think something is definitely wrong with the Flex source code considering this issue.

                  • 6. Re: Flex 4 does not dispatch keyboard events for ENTER key.
                    David_F57 Level 5

                    MikisM87 wrote:

                    I think something is definitely wrong with the Flex source code considering this issue.

                    Maybe its the original build of the SDK with FB beta as I have tried this with all text components both spark and halo with no issue. Btw i'm running the latest nightly sdk on A PC with windows 7 RC x64.

                     

                    Anyway I hope your problem gets resolved I know how frustrating it can be either searching or praying for a resolution.

                     

                    David.

                    • 7. Re: Flex 4 does not dispatch keyboard events for ENTER key.
                      MikisM87 Level 1

                      David_F57 wrote:


                      Maybe its the original build of the SDK with FB beta as I have tried this with all text components both spark and halo with no issue. Btw i'm running the latest nightly sdk on A PC with windows 7 RC x64.

                      Now I'm really confused: I am running the latest nightly SDK also. I've just updated it and spark text components are still not dispatching keyboard events for the ENTER key. Maybe its the Flash Builder but I don't see how the IDE could cause this bug.

                      • 8. Re: Flex 4 does not dispatch keyboard events for ENTER key.
                        Flex harUI Adobe Employee

                        File a bug with your test case.  We'll let our QA make the official determination.

                         

                        Alex Harui

                        Flex SDK Developer

                        Adobe Systems Inc.

                        Blog: http://blogs.adobe.com/aharui