我目前正在开发AIR应用程序,以便检测组合键的命令键,目前我有类似的东西
this.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
protected function onKeyUp(event:KeyboardEvent):void
{
if(event.ctrlKey){
switch(event.keyCode){
case Keyboard.C:
trace("need to copy");
break;
}
}
}
根据docs event.ctrlKey,应该检测mac上的命令和控制键,如果我按下combo控件+ C工作,但如果我用命令+ c什么都没有,我也试过了
event.commandKey
我想也许内置的菜单给了我一些麻烦,我删除然后仍然没有,我缺少什么?谢谢你的帮助
答案 0 :(得分:0)
我也遇到了同样的问题,并通过为剪贴板键添加本机菜单事件来解决此问题。正如您所说的“event.ctrlKey”不适用于MAC和“命令键”与C(复制),V(粘贴),X(剪切),W(关闭),M(最小化)将始终收听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>
我希望这能解决你的问题...