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?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将事件监听器添加到
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:画布不会调度按键向上或按键按下事件。你可以给它们添加一个监听器;因为关键事件将会冒泡;但它不会单独派遣他们。不幸的是,输入组件(例如 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.