AS3禁用键盘文本输入

时间:2013-05-20 15:50:24

标签: actionscript-3 text

我正在制作虚拟键盘,我想找到一种禁用实际键盘的好方法。 无论出于何种原因,除非我的文本字段是基于输入的,否则我的整体代码无效

我尝试了一些简单的东西,但它只在超出范围时才有效..

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

1 个答案:

答案 0 :(得分:1)

尝试

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