espruino / EspruinoDocs

See http://espruino.com for the complete Espruino Documentation - many links in this repository will not work
http://www.espruino.com/
Other
260 stars 284 forks source link

Allow delay arg for type() function #658

Closed BraidenPsiuk closed 2 years ago

BraidenPsiuk commented 2 years ago

Helpful for emulating keyboards on older, slower devices

gfwilliams commented 2 years ago

Thanks, but I'm afraid this will break anyone's code that currently uses USBKeyboard because the arguments changed.

Do you think you could add delay as the last argument so it'll still work? Something like:

exports.type = function(txt, callback, delay) {
  delay = delay||20;
  var intr = setInterval(function() {
    if (!txt.length) {
      clearInterval(intr);
      if (callback) callback();
    } else {
      if (txt[0] in KEY) exports.tap(KEY[txt[0]]);
      txt = txt.substr(1);
    }
  }, delay);
}
BraidenPsiuk commented 2 years ago

Yes, my bad, thanks for catching that!

gfwilliams commented 2 years ago

Great - thanks!