Added disableButtonHold option

This commit is contained in:
Francisco Hodge 2019-06-05 21:08:53 -04:00
parent 5fa612a923
commit 04a3c186f0
3 changed files with 33 additions and 15 deletions

View File

@ -123,6 +123,11 @@ declare module 'simple-keyboard' {
*/ */
useMouseEvents?: boolean; useMouseEvents?: boolean;
/**
* Disable button hold action.
*/
disableButtonHold?: boolean;
/** /**
* Executes the callback function on key press. Returns button layout name (i.e.: "{shift}"). * Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
*/ */

View File

@ -65,6 +65,7 @@ class SimpleKeyboard {
* @property {boolean} autoUseTouchEvents Enable useTouchEvents automatically when touch device is detected. * @property {boolean} autoUseTouchEvents Enable useTouchEvents automatically when touch device is detected.
* @property {boolean} useMouseEvents Opt out of PointerEvents handling, falling back to the prior mouse event logic. * @property {boolean} useMouseEvents Opt out of PointerEvents handling, falling back to the prior mouse event logic.
* @property {function} destroy Clears keyboard listeners and DOM elements. * @property {function} destroy Clears keyboard listeners and DOM elements.
* @property {boolean} disableButtonHold Disable button hold action.
*/ */
this.options = options; this.options = options;
this.options.layoutName = this.options.layoutName || "default"; this.options.layoutName = this.options.layoutName || "default";
@ -245,6 +246,7 @@ class SimpleKeyboard {
/** /**
* @type {object} Time to wait until a key hold is detected * @type {object} Time to wait until a key hold is detected
*/ */
if (!this.options.disableButtonHold) {
this.holdTimeout = setTimeout(() => { this.holdTimeout = setTimeout(() => {
if ( if (
this.isMouseHold && this.isMouseHold &&
@ -262,6 +264,7 @@ class SimpleKeyboard {
clearTimeout(this.holdTimeout); clearTimeout(this.holdTimeout);
}, 500); }, 500);
} }
}
/** /**
* Handles button mouseup * Handles button mouseup

View File

@ -1233,3 +1233,13 @@ it('Keyboard destroy will work', () => {
expect(keyboard.keyboardDOM.innerHTML).toBeFalsy(); expect(keyboard.keyboardDOM.innerHTML).toBeFalsy();
}); });
it('Keyboard disableButtonHold will work', () => {
testUtil.setDOM();
let keyboard = new Keyboard({
disableButtonHold: true
});
expect(keyboard.options.disableButtonHold).toBe(true);
});