1

如何在和keydown 事件上添加事件侦听Ctrl+C器。我正在尝试以下关于按键功能的语句:Ctrl+VCtrl+X

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");
    }
}
4

2 回答 2

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

我正在使用此代码。

于 2012-07-31T11:07:18.067 回答
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;
}
于 2013-12-09T15:09:17.177 回答