views:

358

answers:

1

I am writing an AIR application in Flex. The application needs to be able to handle shortcuts on both Mac and Windows. I have the shortcuts on the Windows side working, but the same application on a Mac doesnt seem to trigger the commandKey property on a Keyboard event when the user is also using another key in combination (ex. command+g doesnt work). What do I need to do to allow me to capture a shortcut on a Mac?

+2  A: 

Hi,

In this basic AIR example I caught both CMD and CTRL keys:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:keyDown>
    <![CDATA[
        trace('CharCode: ' + event.charCode + ' Cmd: ' + event.commandKey + ' Ctrl: ' + event.ctrlKey + ' KeyCode: ' + event.keyCode);
    ]]>
    </mx:keyDown>
    <mx:TextArea />
</mx:WindowedApplication>

I know I had really a lot problem with keyboard events in Flex and either AIR apps because of focus. In the example above you will only see proper results if you click into the Textarea. Maybe this is how it should work by default but I still find keyboard event handling pain in Flex.

itarato
The problem is not catching the cmd and ctrl keys, but catching the cmd key plus another at the some time, like cmd+c for copy. This works in windows using ctrl+c, but not on a mac when you want to use cmd+c. The only thing you get is a keycode=15 (cmd key)
asawilliams