diff --git a/src/lib/components/Keyboard.ts b/src/lib/components/Keyboard.ts index ab0c8475..782cfe2c 100644 --- a/src/lib/components/Keyboard.ts +++ b/src/lib/components/Keyboard.ts @@ -1861,9 +1861,22 @@ class SimpleKeyboard { */ buttonDOM.onclick = (e: KeyboardHandlerEvent) => { this.setMouseHold(false); - this.handleButtonClicked(button, e); + /** + * Fire button handler in onclick for compatibility reasons + * This fires handler before onKeyReleased, therefore when that option is set we will fire the handler + * in onmousedown instead + */ + if(typeof this.options.onKeyReleased !== "function"){ + this.handleButtonClicked(button, e); + } }; buttonDOM.onmousedown = (e: KeyboardHandlerEvent) => { + /** + * Fire button handler for onKeyReleased use-case + */ + if(typeof this.options.onKeyReleased === "function" && !this.isMouseHold){ + this.handleButtonClicked(button, e); + } this.handleButtonMouseDown(button, e); }; buttonDOM.onmouseup = (e: KeyboardHandlerEvent) => {