Flex 3:按键组合触发事件/功能

发布于 2024-11-11 15:49:59 字数 115 浏览 4 评论 0原文

在特定的画布中,我希望用户能够按下组合键来触发事件。(有点像旧的 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?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与往事干杯 2024-11-18 15:49:59

可以将事件监听器添加到KeyboardEvent.KEY_DOWN 事件的顶级应用程序中,并检查那里的按键组合。来自这篇文章

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

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>
情深缘浅 2024-11-18 15:49:59

画布不会调度按键向上或按键按下事件。你可以给它们添加一个监听器;因为关键事件将会冒泡;但它不会单独派遣他们。不幸的是,输入组件(例如 textInput)需要具有焦点才能调度按键事件。

我不使用画布、组或其​​他容器,而是考虑使用 Spark TextInput 具有自定义皮肤,使其和键入的文本基本上不可见。

A canvas won't dispatch key up or key down events. You can add a listener to them; as the key events will bubble; but it won't dispatch them alone. Unfortunately, an input component, such as a textInput, needs to have focus for the key press events to dispatch.

Instead of using a canvas, group, or other container, I'd look into using a Spark TextInput with a customized skin that makes it, and the typed text, essentially invisible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文