Skip to content

Instantly share code, notes, and snippets.

@kzar
Last active August 2, 2016 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzar/6b7348d4154af461e381fddd44d6a023 to your computer and use it in GitHub Desktop.
Save kzar/6b7348d4154af461e381fddd44d6a023 to your computer and use it in GitHub Desktop.
Sending tricky keypresses to webmate.io
// Some keypresses are hard to send to VMs running in webmate.io as they are intercepted
// by the web browser. In those cases you can manually send them. Open the JavaScript console
// and paste one of these snippets.
// Notes:
// - There's a handy sheet of the key codes here http://www.cambiaresearch.com/articles/15/javascript-key-codes.
// - For buttons like Control or Alt you need to use "keydown", but for other keys "keypress".
// - Don't forget to also send a "keyup", otherwise the key will be held down forever!
// Control f
$("#console").wmks("sendKeyCode", 17, "keydown");
$("#console").wmks("sendKeyCode", 70, "keypress");
$("#console").wmks("sendKeyCode", 70, "keyup");
$("#console").wmks("sendKeyCode", 17, "keyup");
// Apple f
$("#console").wmks("sendKeyCode", 91, "keydown");
$("#console").wmks("sendKeyCode", 70, "keypress");
$("#console").wmks("sendKeyCode", 70, "keyup");
$("#console").wmks("sendKeyCode", 91, "keyup");
// FIXME - Needs work, very rough!
function sendString(s)
{
var needShift = "!\"$%^&*()_+}~{@:?<>#ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$("#console").wmks("sendKeyCode", 16, "keyup");
for (let c of s)
{
let shift = needShift.indexOf(c) > -1;
if (shift)
$("#console").wmks("sendKeyCode", 16, "keydown");
$("#console").wmks("sendKeyCode", c.charCodeAt(), "keypress");
if (shift)
$("#console").wmks("sendKeyCode", 16, "keyup");
}
}
sendString("Hello world!! 123");
@kzar
Copy link
Author

kzar commented Jul 14, 2016

The Eyeo Helpers extension now makes this easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment