Action 脚本类中使用了 ctrl 和 space 键吗?
我的动作脚本类中有一个 switch 语句。我有一个 函数 onKeyDown(event: KeyboardEvent)
,其中包含一个 switch 语句。它控制不同的键。 但现在我想使用两个键 CTRL 和 SPACE 键来处理 TAB 键执行的相同功能。 我想在我的 switch 语句中添加一个案例,首先我按 CTRL 键,然后按 SPACE 键,然后调用特定函数。
任何人都可以告诉我 switch 语句中如何使用两个键?
private function onKeyDown(event: KeyboardEvent) : void{
if (popUp.displayPopUp){
switch (event.keyCode){
case Keyboard.UP:
case Keyboard.DOWN:
case Keyboard.END:
case Keyboard.HOME:
case Keyboard.PAGE_UP:
case Keyboard.PAGE_DOWN:
inputTxt.selectRange(text.length, text.length)
list.dispatchEvent(event)
break;
case Keyboard.ENTER:
acceptCompletion();
break;
case Keyboard.TAB:
if (requireSelection)
acceptCompletion();
else
popUp.displayPopUp = false
break;
case Keyboard.ESCAPE:
popUp.displayPopUp = false
break;
case Keyboard.CONTROL && Keyboard.SPACE:
if (requireSelection)
acceptCompletion();
else
popUp.displayPopUp = false
break;
}
}
}
I have a switch statement in my action script class.I have a function onKeyDown(event: KeyboardEvent)
which contain a switch statement.which control the different keys.
But now I want to handle the same functionality which TAB key is doing using two keys CTRL and SPACE key.
I want add a case more in my switch statement first I pressed CTRL and then SPACE key then a a specific function is called.
Anyone can tell me how two keys used in my switch statement?
private function onKeyDown(event: KeyboardEvent) : void{
if (popUp.displayPopUp){
switch (event.keyCode){
case Keyboard.UP:
case Keyboard.DOWN:
case Keyboard.END:
case Keyboard.HOME:
case Keyboard.PAGE_UP:
case Keyboard.PAGE_DOWN:
inputTxt.selectRange(text.length, text.length)
list.dispatchEvent(event)
break;
case Keyboard.ENTER:
acceptCompletion();
break;
case Keyboard.TAB:
if (requireSelection)
acceptCompletion();
else
popUp.displayPopUp = false
break;
case Keyboard.ESCAPE:
popUp.displayPopUp = false
break;
case Keyboard.CONTROL && Keyboard.SPACE:
if (requireSelection)
acceptCompletion();
else
popUp.displayPopUp = false
break;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个很常见的问题。
event.keyCode
只会为您提供最近按下的键的 keyCode。因此,您必须存储按键操作和按键释放操作。幸运的是,AS3 是一个非常好的数组实现,可以轻松完成此操作。这使您可以拥有一个整洁的小数组,它总是告诉您按下了哪些键。它还将程序逻辑与输入逻辑分开。双赢。
This is a pretty common problem.
event.keyCode
is only going to give you the keyCode for the most recent key pressed. So you will have to store key presses and key releases. Fortunately, AS3 is a pretty sweet Array implementation that allows this to be done easily.This allows you to have a neat little array that always tells you what keys are down. It also separates your program logic from your input logic. Double win.
在您的情况下,您只需检查 键盘事件。但@DingoEatingFuzz 的答案将允许检查“空格”+“字母”等组合。
In your case you can just check
ctrlKey
property on KeyboardEvent. But @DingoEatingFuzz's answer will allow check combinations like 'space' + 'letter' and so on.案例键盘.SPACE:
if (事件.ctrlKey)
{
}
休息;
我认为这个方法很好......
case Keyboard.SPACE:
if (event.ctrlKey)
{
}
break;
i think this one approch is good........