本文介绍了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
事件,并在其中检查键组合.摘自本文:
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:按键组合触发事件/功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!