0

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

我尝试了一些简单的方法,但它仅在超出范围时才有效..

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

1 回答 1

1

尝试

stage.addEventListener(KeyboardEvent.KEY_DOWN, blindKeyboard);
stage.addEventListener(KeyboardEvent.KEY_UP, blindKeyboard);
function blindKeyboard(e:KeyboardEvent):void{
    e.preventDefault();
    e.stopPropagation();
}
于 2013-05-20T15:52:13.753 回答