kingBook

导航

LayaAir3.x 侦听键盘事件

const { regClass, property } = Laya;

@regClass()
export class Test extends Laya.Script {
    
    declare owner: Laya.Sprite;
    
    onAwake(): void {
        this.owner.on(Laya.Event.KEY_DOWN,this, this.onKeyDown);
    }
    
    private onKeyDown(e:Laya.Event):void{
        if(e.keyCode === Laya.Keyboard.A){
            console.log("A");
        }
    }
    
}

posted on 2025-02-15 03:01  kingBook  阅读(5)  评论(0)    收藏  举报