Last active
August 2, 2016 22:16
-
-
Save kzar/6b7348d4154af461e381fddd44d6a023 to your computer and use it in GitHub Desktop.
Sending tricky keypresses to webmate.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Eyeo Helpers extension now makes this easier.