Sme Posted November 25, 2018 Share Posted November 25, 2018 onBeforeKeyAddObservable doesn't pick up Enter presses, and onBlurAddObservable doesn't differentiate between the user pressing Enter and clicking outside of the TextInput. What I'm trying to do is have a chat box, so that the user can send the message simply by pressing Enter; but I can't find a way to determine when the user actually presses Enter. Thanks Quote Link to comment Share on other sites More sharing options...
Sme Posted November 25, 2018 Author Share Posted November 25, 2018 Answering my own question... The solution I came up with was remove the event listeners from the InputText, and add a 'keydown' event listener to the canvas. Then in the canvas' keydown event, if the user presses enter, I process the chat input's current text and then clear it. Otherwise, I call the InputText.processKeyboard(e) method, with e being the KeyboardEvent passed via the onkeydown event, and let the InputText control process it from there. private _chatInput : GUI.InputText; ... document.getElementById('canvas').addEventListener('keydown', this._handleKeyDown.bind(this)); ... private _handleKeyDown(e : KeyboardEvent) : void { if (this._chatInput) { if (e.key === 'Enter') { this._chatInput.text = ''; } else { this._chatInput.processKeyboard(e); } } } Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 26, 2018 Share Posted November 26, 2018 You could try this to not break the underlying handlers: https://www.babylonjs-playground.com/#UWS0TS#23 Basically detecting the next enter after onBlur to be sure. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.