Class
KeyboardPlugin
View sourceExtendsPlugin
Adds keyboard input support to an App.
KeyboardPlugin provides a Keyboard resource in the app’s default
world. Read it to query held KeyCode values and detect keys that
were just pressed or released.
The plugin consumes typed KeyDown and KeyUp events from
WindowPlugin. Recognized browser code values map to
KeyCode values; unsupported codes use
KeyCode.Unidentified. KeyboardPlugin does not attach browser
listeners itself. In a browser application, add DOMWindowPlugin to
bridge native keyboard events into the window event resources.
KeyboardPlugin requires CorePlugin, ReflectPlugin, and
WindowPlugin. Register those dependencies before
App#run; the app validates dependencies but does not install them
automatically.
Examples
import { App } from '@wimaengine/app'
import { CorePlugin } from '@wimaengine/core'
import { Keyboard, KeyboardPlugin, KeyCode } from '@wimaengine/keyboard'
import { ReflectPlugin } from '@wimaengine/reflect'
import { DOMWindowPlugin } from '@wimaengine/window-dom'
import { WindowPlugin } from '@wimaengine/window'
const app = new App()
.registerPlugin(new ReflectPlugin())
.registerPlugin(new CorePlugin())
.registerPlugin(new WindowPlugin())
.registerPlugin(new KeyboardPlugin())
.registerPlugin(new DOMWindowPlugin())
app.run()
const keyboard = app.getWorld().getResource(Keyboard)
if (keyboard.justPressed(KeyCode.Space)) {
console.log('Space started')
}
if (keyboard.pressed(KeyCode.ArrowLeft)) {
console.log('Move left')
}Constructor
Methods
register(app: App): void
View sourcerequires(): TypeId[]
View sourceReturns the plugin dependencies required for keyboard input.
The returned IDs identify CorePlugin, ReflectPlugin,
and WindowPlugin. WindowPlugin provides the typed
KeyDown and KeyUp events consumed by this plugin.
