3 Replies Latest reply on Jun 21, 2010 2:21 AM by BBCLX

    Detecting Mac command key

    SilentChris

      Is there a way in AIR currently to detect when a user is using the command modifier key on a mac?  Detecting control and shift seem to work fine, but KeyboardEvent.commandKey is always false.

       

      I noticed under the flash.ui.Keyboard class, the COMMAND constant has the note: " This constant is currently only used for setting menu key equivalents."  Does that mean that AIR doesn't support detecting the command modifier key as part of a KeyboardEvent?

        • 1. Re: Detecting Mac command key
          Joe ... Ward Level 4

          The KeyboardEvent.commandKey property works correctly for me.

          • 2. Re: Detecting Mac command key
            SilentChris Level 1

            Ahh - apparently the command key can be detected on a keyDown event, but not on a keyUp event (although the ctrlKey detection seems to work on keyUp).  Changing the handler to keyDown worked for me.  Example app below:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                <mx:Canvas x="10" y="10" width="782" height="410" backgroundColor="#CCCCCC">
                    <mx:TextInput keyDown="handleKeyDown(event)" keyUp="handleKeyUp(event)" x="10" y="378" width="762"/>
                    <mx:VBox id="key_infos" x="10" y="10" width="400">
                    </mx:VBox>
                </mx:Canvas>
                <mx:Script>
                    <![CDATA[
                        import mx.controls.Label;
                        internal function handleKeyDown(e:KeyboardEvent):void {
                            if (e.commandKey) {
                                var l:Label = new Label();
                                l.text = 'key down - holding cmd key';
                                key_infos.addChild(l);
                            }    
                        }
                        
                        internal function handleKeyUp(e:KeyboardEvent):void {
                            if (e.commandKey) {
                                var l:Label = new Label();
                                l.text = 'key up - holding cmd key';
                                key_infos.addChild(l);
                            }    
                        }
                    ]]>
                </mx:Script>
            </mx:WindowedApplication>
            
            
            
            • 3. Re: Detecting Mac command key
              BBCLX

              I could make it work on OSX, but not on Windows, where I get a strange behaviour: http://forums.adobe.com/message/2718032#2718032

               

              Please help.