diff --git a/packages/graphics/stage.js b/packages/graphics/stage.js index a24a8a9..172f951 100644 --- a/packages/graphics/stage.js +++ b/packages/graphics/stage.js @@ -44,6 +44,8 @@ export class Stage extends decorate(Container) { // Normalize input. this.inputNormalizer = new InputNormalizer(); this.inputNormalizer.listen(this.element); + this.inputNormalizer.on('keyDown', this.onKeyDown, this); + this.inputNormalizer.on('keyUp', this.onKeyUp, this); this.inputNormalizer.on('pointerDown', this.onPointerDown, this); this.inputNormalizer.on('pointerMove', this.onPointerMove, this); this.inputNormalizer.on('pointerUp', this.onPointerUp, this); @@ -86,9 +88,11 @@ export class Stage extends decorate(Container) { if (this.parent) { this.parent.removeChild(this.renderer.element); } - this.inputNormalizer.off('pointerDown', this.onPointerDown, this); - this.inputNormalizer.off('pointerMove', this.onPointerMove, this); - this.inputNormalizer.off('pointerUp', this.onPointerUp, this); + this.inputNormalizer.off('keyDown', this.onKeyDown); + this.inputNormalizer.off('keyUp', this.onKeyUp); + this.inputNormalizer.off('pointerDown', this.onPointerDown); + this.inputNormalizer.off('pointerMove', this.onPointerMove); + this.inputNormalizer.off('pointerUp', this.onPointerUp); this.inputNormalizer.destroy(); } @@ -128,6 +132,14 @@ export class Stage extends decorate(Container) { this.element.focus(); } + onKeyDown(event) { + this.emit('keyDown', event); + } + + onKeyUp(event) { + this.emit('keyUp', event); + } + onPointerDown(event) { event.position = this.transformCanvasPosition(event.position); this.emit('pointerDown', event);