如何在 Ctrl + C , Ctrl + V 和 Ctrl + X keydown事件中添加事件侦听器。我正在尝试以下关于关键功能的声明:
public function OnKeyDown(e:KeyboardEvent){
if((e.ctrlKey && (e.keyCode == Keyboard.C)) {
trace ("copy");
}else if((e.ctrlKey && (e.keyCode == Keyboard.V)) {
trace ("paste");
}else if((e.ctrlKey && (e.keyCode == Keyboard.X)) {
trace ("cut");
}
}
答案 0 :(得分:3)
systemManager.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
protected function onKeyUp(event:KeyboardEvent):void
{
if (event.ctrlKey)
switch(event.keyCode)
{
case 67: break; //Keyboard.C
case 86: break; //Keyboard.V
case 88: break; //Keyboard.X
}
}
我正在使用此代码。
答案 1 :(得分:0)
嗨,我认为它工作正常:
stage.addEventListener(KeyboardEvent.KEY_DOWN,onkeydown)
function onkeydown(e:KeyboardEvent)
{
if(e.ctrlKey)
{
stage.addEventListener(KeyboardEvent.KEY_UP,onkeyup)
}
}
function onkeyup(e:KeyboardEvent)
{
if (e.keyCode == 88)
{
trace("You pressed Ctrl+X");
}
else if (e.keyCode == 67)
{
trace("You pressed Ctrl+c");
}
else if (e.keyCode == 86 )
{
trace("You pressed Ctrl+v");
}
e.ctrlKey=false;
}