Tropzilla
Tropzilla

Reputation: 25

AS3 Disabling keyboard text input

I'm making a virtual keyboard, and I want to find a good way to disable the actual keyboard. For whatever reason my overall code doesnt work unless my text fields are input based.

I tried something simple with this, but it only works when its out of scope..

stage.addEventListener(KeyboardEvent.KEY_UP, onKeyEvent);

function onKeyEvent(e:KeyboardEvent):void
{
    var character:String = String.fromCharCode(e.charCode);

    if (e.keyCode == 65)
    {
        trace(character);  
    }
    else if (e.keyCode == 66)
    {
        trace(character);  
    }
        else if (e.keyCode == 67)
    {
        trace(character);   
    }
        else if (e.keyCode == 68)
    {
        trace(character);  
    }
        else if (e.keyCode == 69)
    {
        trace(character);  
    }
        else if (e.keyCode == 70)
    {
        trace(character);  
    }
        else if (e.keyCode == 71)
    {
        trace(character);  
    }
        else if (e.keyCode == 72)
    {
        trace(character); 
    }
        else if (e.keyCode == 66)
    {
        trace(character);   
    }
}

Upvotes: 0

Views: 861

Answers (1)

codingbuddha
codingbuddha

Reputation: 707

Try

stage.addEventListener(KeyboardEvent.KEY_DOWN, blindKeyboard);
stage.addEventListener(KeyboardEvent.KEY_UP, blindKeyboard);
function blindKeyboard(e:KeyboardEvent):void{
    e.preventDefault();
    e.stopPropagation();
}

Upvotes: 1

Related Questions