按键组合触发事件

按键组合触发事件

本文介绍了Flex 3:按键组合触发事件/功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在特定的画布中,我希望用户能够按下将触发事件的组合键.(有点像旧版megadrive 游戏中的作弊).不知道从哪里开始.任何人都知道是否有可能,如果有,你能给我一个如何开始的线索吗?

Within a specific canvas, I would like a user to be able to press a combination of keys which will trigger an event.(a bit like a cheat in an old megadrive game). Not sure where to start though. Anyone know if it is possible and if so could you give me a clue with how to start?

提前致谢!

推荐答案

可以KeyboardEvent.KEY_DOWN 事件添加一个 eventListener 到顶级应用程序并检查那里的组合键.来自这篇文章:

You can add an eventListener to the top level application for the KeyboardEvent.KEY_DOWN event and check for key combinations there. From this article:

<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>

这篇关于Flex 3:按键组合触发事件/功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:09