-
-
Notifications
You must be signed in to change notification settings - Fork 309
Keyboard Input design
AZhan edited this page Feb 28, 2022
·
4 revisions
When implementing the input system, we made compatibility for all inputs, this keyboard event can be implemented very simply. Input system design
class Script
{
.......
/**
* Called when the keyboard is pressed.
*/
onKeyDown(key:KeyEvent): void {}
/**
* Called when the keyboard is up.
*/
onKeyUp(key:KeyEvent): void {}
......
}
/**
* Input Manager.
*/
export class InputManager {
// Whether the button is being held down.
getKey(keyCode:string): Boolean {}
// Whether the current frame triggers a key press.
getKeyDown(keyCode:string): Boolean {}
// Whether the current frame triggers a key Up.
getKeyUp(keyCode:string): Boolean {}
}
/**
* Description of key information.
*/
export class Key {
keyCode: string;
}