添加键盘快捷键,Flex应用程序 [英] Adding key board shortcuts to a flex application

查看:120
本文介绍了添加键盘快捷键,Flex应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多自定义组件的Flex应用程序,如自定义按钮,组合框等,我想补充的键盘快捷方式Flex应用程序。在此过程中,我添加了一个键被按下监听器应用程序来监听 Ctrl + Shift 这样的组合键:

I have a flex app with lots of custom components, like custom buttons, comboBoxes etc. I am trying to add keyBoard shortcuts to the flex app. In doing so, I added a key-down listener to the app to listen for ctrl+shift key combination like this:

this.stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);

然后,我派遣我所有的自定义组件被监听自定义事件:

then I dispatch a custom event that all of my custom components are listening for:

private function reportKeyDown(event:KeyboardEvent):void
{
    var evtObj:Object = new Object();
    evtObj.keyEvent = event;
    dispatchEvent(new CustomEvent(CustomEvent.SHORTCUT_KEYS_PRESSED, evtObj, true, false));
}

在我的自定义按钮组件,我有:

In my custom button component I have:

this.addEventListener(CustomEvent.SHORTCUT_KEYS_PRESSED, ShortCutKeysHandler, true);

所以,如果我走了 Ctrl + Shift + W 那么我想获得点击自定义按钮的一个实例。

So, if I go ctrl+shift+W then I want one instance of the custom button to get clicked.

由于某些原因,该事件永远不会被触发,并且不会继续执行 ShortCutKeysHandler 的功能。

For some reason, the event never gets triggered and never gets to the ShortCutKeysHandler function.

有谁知道如何做到这一点?

Does anyone know how to do this?

推荐答案

我的猜测是,你的事件不冒泡的听众。如果您仔细观察键盘事件,并且不需要任何额外的负载,或许会简单地听你感兴趣的组件级事件,或者有舞台调度自定义事件并使用的阶段更有效.addEventListener 的在你感兴趣的组件,而不是的 this.addEventListener 的。

My guess is that your event isn't bubbling to the listeners. If you are strictly looking for keyboard events, and don't need any additional payload, perhaps it would be more effective to simply listen for the stage events in your interested components, alternatively have the stage dispatch your custom event and use stage.addEventListener in your interested components instead of this.addEventListener.

根据约定,我的永远的依赖于事件冒泡。它混淆你的应用程序,并引起混淆。这是更好地明确地定义您的事件结构,以获得您的应用程序的更多控制,使调试更加容易。

As a convention, I never rely on event bubbling. It obfuscates your application and creates ambiguity. It is better to explicitly define your event structure to gain additional control of your application and make debugging much easier.

这篇关于添加键盘快捷键,Flex应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆