Core. KeyBoardManager

KeyBoardManager Keyboard event management class. This class receives the keyboard event from the browser and distributes the event.

When an event is dispatched, if the Stage.focus is empty, the event is distributed only from the Stage, otherwise the event will begin to be bubbling from the Stage.focus object. Therefore, listening to keyboard events on the Laya.stage can be received. If you listen elsewhere, you must be on the Stage.focus bubble chain to receive the event.

The user can set the focus object in the way of code Laya.stage.focus=someNode.

The user can uniformly determine the key type based on the e.keyCode in the event object, which is compatible with the implementation of different browsers.


new KeyBoardManager()


(static) enabled :Boolean

The keyboard event is turned on and defaults to true


hasKeyDown(key) → {Boolean}

Returns whether the specified key is pressed.
Name Type Description
key int Key value.
Is it pressed?.