Support for control bindings with user-defined values (eg, for Keyboard "test" button)

This commit is contained in:
Jeff Parsons 2016-02-02 10:21:45 -08:00
commit 4ab2c21043
32 changed files with 2374 additions and 2253 deletions

View file

@ -970,15 +970,16 @@ Keyboard.LIMIT = {
};
/**
* setBinding(sHTMLType, sBinding, control)
* setBinding(sHTMLType, sBinding, control, sValue)
*
* @this {Keyboard}
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea", "canvas")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "esc")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
Keyboard.prototype.setBinding = function(sHTMLType, sBinding, control)
Keyboard.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
/*
* There's a special binding that the Video component uses ("kbd") to effectively bind its
@ -1047,6 +1048,14 @@ Keyboard.prototype.setBinding = function(sHTMLType, sBinding, control)
};
return true;
case "test":
this.bindings[id] = control;
control.onclick = function onClickTest(event) {
if (kbd.cpu) kbd.cpu.setFocus();
return kbd.injectKeys(sValue);
};
return true;
default:
/*
* Maintain support for older button codes; eg, map button code "ctrl-c" to CLICKCODE "CTRL_C"
@ -1562,17 +1571,19 @@ Keyboard.prototype.addScanCode = function(bScan)
};
/**
* injectKeys(sKeyCodes, msDelay)
* injectKeys(sKeys, msDelay)
*
* @this {Keyboard}
* @param {string} sKeyCodes
* @param {number|undefined} [msDelay] is an optional injection delay (default is msInjectDelay)
* @param {string|undefined} sKeys
* @param {number} [msDelay] is an optional injection delay (default is msInjectDelay)
*/
Keyboard.prototype.injectKeys = function(sKeyCodes, msDelay)
Keyboard.prototype.injectKeys = function(sKeys, msDelay)
{
this.sInjectBuffer = sKeyCodes;
if (!COMPILED) this.log("injectKeys(" + this.sInjectBuffer.split("\n").join("\\n") + ")");
this.injectKeysFromBuffer(msDelay || this.msInjectDelay);
if (sKeys && !this.sInjectBuffer) {
this.sInjectBuffer = sKeys;
if (!COMPILED) this.log("injectKeys(" + this.sInjectBuffer.split("\n").join("\\n") + ")");
this.injectKeysFromBuffer(msDelay || this.msInjectDelay);
}
};
/**