在监听键盘事件之前,让舞台获得焦点是必要的,加一个单击事件来变通一下
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Script> <![CDATA[ private function init():void{ this.addEventListener(MouseEvent.CLICK, clickHandler); this.addEventListener(KeyboardEvent.KEY_DOWN,keyPressed); } private function clickHandler(event:MouseEvent):void { stage.focus = this; } private function keyPressed(evt:KeyboardEvent):void{ if(evt.ctrlKey && evt.keyCode == 65) trace("CTRL A is pressed"); if(evt.ctrlKey && evt.keyCode == 66) trace("CTRL B is pressed"); } ]]> </mx:Script> </mx:Application>