Actionscript 3.0 KEY_DOWN仅适用于某些键

时间:2013-12-05 01:21:58

标签: actionscript-3 keyboard-events

所以我是Actionscript 3的新手,我正在尝试制作与键盘键A到K相对应的钢琴。我写了一些脚本(如下所示)来检查KEY_DOWN事件,但它没有适用于大多数小写字母。所有大写字母,数字和其他键都正确地跟踪和重置aPlay,但是对于小写字母,只有w,d,x u和g似乎有效。我做错了什么?

//aKey is an object defined outside the script that works fine.
stop();

var aPlay:int = 1;
aKey.alpha = 0.1*aPlay;

this.stage.addEventListener(KeyboardEvent.KEY_DOWN, playPiano);
this.stage.addEventListener( Event.ENTER_FRAME, this._onUpdate );

function playPiano(e:KeyboardEvent):void{
    //if(e.keyCode == 65)//Commented out for now
        aPlay = 5;

    trace(e.keyCode);//Debug
}

function _onUpdate( e:Event ):void
{
    aKey.alpha = 0.2*aPlay;

    if (aPlay > 1){
        aPlay--;
    }
}

1 个答案:

答案 0 :(得分:0)

package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

public class Test_Keyboard extends Sprite{
    public function Test_Keyboard() {
        stage.addEventListener(KeyboardEvent.KEY_DOWN, trEvent)
    }

    private function trEvent(event:KeyboardEvent):void {
        trace(event.keyCode, event.shiftKey, event.charCode)

        switch (event.charCode)
        {
            case Keyboard.A:
                trace("A")
                break;
            case 97: 
                trace("a")
                break;
        }
    }
}

}

没有找到charCode表,只是跟踪它。