我也遇到了同样的问题,并通过为剪贴板键添加本机菜单事件来解决此问题。正如您所说,“event.ctrlKey”不适用于 MAC,而“命令键”与 C(copy)、V(paste)、X(cut)、W(close)、M(minimize) 结合使用将始终收听AIR 应用程序的本机菜单事件(buildIn 菜单事件)。所以我添加了菜单选择事件。
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="windowedapplication1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
this.addEventListener(KeyboardEvent.KEY_DOWN, onKey_PressHandler);
}
protected function onKey_PressHandler(event:KeyboardEvent):void
{
// for mac only statements
if(isMAC())
{
if(NativeApplication.supportsMenu){
if(event.keyCode == Keyboard.COMMAND)
{
if(event.type == KeyboardEvent.KEY_DOWN)
{
NativeApplication.nativeApplication.menu.addEventListener(Event.SELECT,onApplicationMenu_ClickHandler);
}
else
{
// remove event if it is no longer needed
NativeApplication.nativeApplication.menu.removeEventListener(Event.SELECT,onApplicationMenu_ClickHandler);
}
}
}
}
}
protected function onApplicationMenu_ClickHandler(event:Event):void
{
var menuItem:NativeMenuItem = event.target as NativeMenuItem;
switch(menuItem.label)
{
case "cut":
// do cut operation
trace("COMMAND + X");
break;
case "copy":
// do copy operation
trace("COMMAND + C");
break;
case "paste":
// do paste operation
trace("COMMAND + V");
break;
}
}
private function isMAC():Boolean
{
return (Capabilities.version.substr(0,3) == "mac");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:WindowedApplication>
我希望这能解决你的问题...