diff --git a/src/Input.ts b/src/Input.ts index 3399e0dd..25c69fc6 100644 --- a/src/Input.ts +++ b/src/Input.ts @@ -55,6 +55,7 @@ export class Input extends Container protected placeholder: PixiText; protected editing = false; protected tick = 0; + protected lastInputData: string; protected activation = false; protected readonly options: InputOptions; @@ -63,6 +64,7 @@ export class Input extends Container protected handleActivationBinding = this.handleActivation.bind(this); protected onKeyUpBinding = this.onKeyUp.bind(this); protected stopEditingBinding = this.stopEditing.bind(this); + protected onInputBinding = this.onInput.bind(this); /** Fires when input loses focus. */ onEnter: Signal<(text: string) => void>; @@ -126,6 +128,8 @@ export class Input extends Container window.addEventListener('click', this.handleActivationBinding); window.addEventListener('keyup', this.onKeyUpBinding); + + window.addEventListener('input', this.onInputBinding as EventListener); } this.onEnter = new Signal(); @@ -143,6 +147,11 @@ export class Input extends Container } } + protected onInput(e: InputEvent) + { + this.lastInputData = e.data; + } + protected onKeyUp(e: KeyboardEvent) { const key = e.key; @@ -155,7 +164,13 @@ export class Input extends Container { this.stopEditing(); } - else if (key.length === 1) this._add(key); + else if (key.length === 1) + { + this._add(key); + } + else if (this.lastInputData && this.lastInputData.length === 1) { + this._add(this.lastInputData); + } } protected init() @@ -332,6 +347,7 @@ export class Input extends Container { this.input.removeEventListener('blur', this.stopEditingBinding); this.input.removeEventListener('keyup', this.onKeyUpBinding); + this.input.removeEventListener('input', this.onInputBinding as EventListener); this.input?.blur(); this.input?.remove(); @@ -369,6 +385,7 @@ export class Input extends Container input.addEventListener('blur', this.stopEditingBinding); input.addEventListener('keyup', this.onKeyUpBinding); + input.addEventListener('input', this.onInputBinding as EventListener); this.input = input; @@ -558,6 +575,8 @@ export class Input extends Container window.removeEventListener('click', this.handleActivationBinding); window.removeEventListener('keyup', this.onKeyUpBinding); + + window.removeEventListener('input', this.onInputBinding as EventListener); } super.destroy(options);