Ajay Kumar
Ajay Kumar

Reputation: 67

CTRL + C, CTRL + V and CTRL + X event listener

How to add the event listener on Ctrl+C, Ctrl+V and Ctrl+X keydown event. I am try the statement as given below on the key down function:

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

Upvotes: 1

Views: 10647

Answers (2)

user3083344
user3083344

Reputation: 1

Hi I think that it's working Fine:

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

Upvotes: 0

Alex
Alex

Reputation: 907

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

I am using this code.

Upvotes: 4

Related Questions