Mercurial > hg > rlgwebd
changeset 70:d7eb63cd7a16
Try to get some compatibility for keys.
I'd thought using the DOM_VK_ names was a good idea. Symbolic names
ought to be more portable than opaque numeric constants. Foolish me,
expecting things to be sane.
Keys now work with FF15 and Chrome 17.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Thu, 21 Jun 2012 09:43:52 -0700 |
parents | 0c16f07135dd |
children | fc8cbf20e04c |
files | rlgterm.js shterm.js termemu-keys.js |
diffstat | 3 files changed, 54 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/rlgterm.js Wed Jun 20 14:14:22 2012 -0700 +++ b/rlgterm.js Thu Jun 21 09:43:52 2012 -0700 @@ -269,8 +269,8 @@ return; var keynum = ev.keyCode; var code; - if (keynum >= ev.DOM_VK_A && keynum <= ev.DOM_VK_Z) { - /* Letters. This assumes the codes are 65-90. */ + if (keynum >= 65 && keynum <= 90) { + /* Letters. */ if (ev.ctrlKey) keynum -= 64; else if (!ev.shiftKey) @@ -279,7 +279,7 @@ if (code.length < 2) code = "0" + code; } - else if (keynum >= ev.DOM_VK_0 && keynum <= ev.DOM_VK_9) { + else if (keynum >= 48 && keynum <= 57) { /* The number row, NOT the numpad. */ if (ev.shiftKey) { code = numShifts[keynum - 48].toString(16); @@ -294,8 +294,8 @@ else code = keyHexCodes[keynum][0]; } - else if (keynum == ev.DOM_VK_SHIFT || keynum == ev.DOM_VK_CONTROL || - keynum == ev.DOM_VK_ALT || keynum == ev.DOM_VK_CAPS_LOCK) { + else if (keynum >= 16 && keynum <= 20) { + /* Shift, Cntl, Alt, CAPSLOCK */ return; } else {
--- a/shterm.js Wed Jun 20 14:14:22 2012 -0700 +++ b/shterm.js Thu Jun 21 09:43:52 2012 -0700 @@ -213,8 +213,8 @@ function sendkey(ev) { var keynum = ev.keyCode; var code; - if (keynum >= ev.DOM_VK_A && keynum <= ev.DOM_VK_Z) { - /* Letters. This assumes the codes are 65-90. */ + if (keynum >= 65 && keynum <= 90) { + /* Letters. */ if (ev.ctrlKey) keynum -= 64; else if (!ev.shiftKey) @@ -223,7 +223,7 @@ if (code.length < 2) code = "0" + code; } - else if (keynum >= ev.DOM_VK_0 && keynum <= ev.DOM_VK_9) { + else if (keynum >= 48 && keynum <= 57) { /* The number row. */ if (ev.shiftKey) { code = numShifts[keynum - 48].toString(16); @@ -238,8 +238,7 @@ else code = keyHexCodes[keynum][0]; } - else if (keynum == ev.DOM_VK_SHIFT || keynum == ev.DOM_VK_CONTROL || - keynum == ev.DOM_VK_ALT || keynum == ev.DOM_VK_CAPS_LOCK) { + else if (keynum >= 16 && keynum <= 20) { return; } else { @@ -298,7 +297,7 @@ else return; //writeData("Sending " + keystr); - var formdata = {"t": "d", "n": nsend++, "d": code}; + var formdata = {"t": "d", "n": nsend++, "d": keystr}; var datareq = new XMLHttpRequest(); datareq.onreadystatechange = postResponseHandler; datareq.open('POST', '/feed', true);
--- a/termemu-keys.js Wed Jun 20 14:14:22 2012 -0700 +++ b/termemu-keys.js Thu Jun 21 09:43:52 2012 -0700 @@ -5,25 +5,29 @@ var keyHexCodes = { init: function () { - this[KeyboardEvent.DOM_VK_RETURN] = ["0d", "0d"]; - this[KeyboardEvent.DOM_VK_SPACE] = ["20", "20"]; - this[KeyboardEvent.DOM_VK_TAB] = ["09", "09"]; - this[KeyboardEvent.DOM_VK_BACK_QUOTE] = ["60", "7e"]; - this[KeyboardEvent.DOM_VK_OPEN_BRACKET] = ["5b", "7b"]; - this[KeyboardEvent.DOM_VK_CLOSE_BRACKET] = ["5d", "7d"]; - this[KeyboardEvent.DOM_VK_BACK_SLASH] = ["5c", "7c"]; - this[KeyboardEvent.DOM_VK_SEMICOLON] = ["3b", "3a"]; - this[KeyboardEvent.DOM_VK_QUOTE] = ["27", "22"]; - this[KeyboardEvent.DOM_VK_COMMA] = ["2c", "3c"]; - this[KeyboardEvent.DOM_VK_PERIOD] = ["2e", "3e"]; - this[KeyboardEvent.DOM_VK_SLASH] = ["2f", "3f"]; - this[KeyboardEvent.DOM_VK_EQUALS] = ["3d", "2b"]; - this[KeyboardEvent.DOM_VK_SUBTRACT] = ["2d", "5f"]; - this[KeyboardEvent.DOM_VK_BACK_SPACE] = ["08", "08"]; - this[KeyboardEvent.DOM_VK_DELETE] = ["1b5b337e", "1b5b337e"]; - this[KeyboardEvent.DOM_VK_ESCAPE] = ["1b", "1b"]; - this[KeyboardEvent.DOM_VK_PAGE_UP] = ["1b5b357e", "1b5b357e"]; - this[KeyboardEvent.DOM_VK_PAGE_DOWN] = ["1b5b367e", "1b5b367e"]; + this[13] = ["0d", "0d"]; // return + this[32] = ["20", "20"]; // space + this[9] = ["09", "09"]; // tab + this[192] = ["60", "7e"]; // backtick, tilde + this[219] = ["5b", "7b"]; // open bracket, open brace + this[221] = ["5d", "7d"]; // close bracket, close brace + this[220] = ["5c", "7c"]; // backslash, pipe + this[59] = ["3b", "3a"]; // semicolon, colon + this[186] = ["3b", "3a"]; // semicolon, colon (Chrome) + this[222] = ["27", "22"]; // single quote, double quote + this[188] = ["2c", "3c"]; // comma, less than + this[190] = ["2e", "3e"]; // period, right angle + this[191] = ["2f", "3f"]; // slash, question mark + this[61] = ["3d", "2b"]; // equal, plus + this[187] = ["3d", "2b"]; // equal, plus (Chrome) + this[109] = ["2d", "5f"]; // subtract, underscore (maybe on numpad) + this[173] = ["2d", "5f"]; // subtract, underscore (maybe not on numpad) + this[189] = ["2d", "5f"]; // subtract, underscore (Chrome) + this[8] = ["08", "08"]; // backspace + this[46] = ["1b5b337e", "1b5b337e"]; // delete + this[27] = ["1b", "1b"]; // escape + this[33] = ["1b5b357e", "1b5b357e"]; // page up + this[34] = ["1b5b367e", "1b5b367e"]; // page down this.appCursor(false); this.appKeypad(false); }, @@ -31,20 +35,20 @@ appCursor: function (on) { /* Aren't special keys vile? */ if (on) { - this[KeyboardEvent.DOM_VK_LEFT] = ["1b4f44", "1b4f44"]; - this[KeyboardEvent.DOM_VK_RIGHT] = ["1b4f43", "1b4f43"]; - this[KeyboardEvent.DOM_VK_UP] = ["1b4f41", "1b4f41"]; - this[KeyboardEvent.DOM_VK_DOWN] = ["1b4f42", "1b4f42"]; - this[KeyboardEvent.DOM_VK_END] = ["1b4f46", "1b4f46"]; - this[KeyboardEvent.DOM_VK_HOME] = ["1b4f48", "1b4f48"]; + this[37] = ["1b4f44", "1b4f44"]; // left arror + this[39] = ["1b4f43", "1b4f43"]; // right arrow + this[38] = ["1b4f41", "1b4f41"]; // up arrow + this[40] = ["1b4f42", "1b4f42"]; // down arrow + this[35] = ["1b4f46", "1b4f46"]; // end + this[36] = ["1b4f48", "1b4f48"]; // home } else { - this[KeyboardEvent.DOM_VK_LEFT] = ["1b5b44", "1b5b44"]; - this[KeyboardEvent.DOM_VK_RIGHT] = ["1b5b43", "1b5b43"]; - this[KeyboardEvent.DOM_VK_UP] = ["1b5b41", "1b5b41"]; - this[KeyboardEvent.DOM_VK_DOWN] = ["1b5b42", "1b5b42"]; - this[KeyboardEvent.DOM_VK_END] = ["1b5b46", "1b5b46"]; - this[KeyboardEvent.DOM_VK_HOME] = ["1b5b48", "1b5b48"]; + this[37] = ["1b5b44", "1b5b44"]; // left arror + this[39] = ["1b5b43", "1b5b43"]; // right arrow + this[38] = ["1b5b41", "1b5b41"]; // up arrow + this[40] = ["1b5b42", "1b5b42"]; // down arrow + this[35] = ["1b5b46", "1b5b46"]; // end + this[36] = ["1b5b48", "1b5b48"]; // home } }, appKeypad: function (on) { @@ -52,15 +56,15 @@ * sequences. Since we can't count on the terminfo description actually * containing those sequences, pretend they're just arrow keys etc. */ - this[KeyboardEvent.DOM_VK_NUMPAD1] = ["1b4f46", "1b4f46"]; - this[KeyboardEvent.DOM_VK_NUMPAD2] = ["1b4f42", "1b4f42"]; - this[KeyboardEvent.DOM_VK_NUMPAD3] = ["1b5b367e", "1b5b367e"]; - this[KeyboardEvent.DOM_VK_NUMPAD4] = ["1b4f44", "1b4f44"]; - this[KeyboardEvent.DOM_VK_NUMPAD5] = ["1b5b45", "1b5b45"]; - this[KeyboardEvent.DOM_VK_NUMPAD6] = ["1b4f43", "1b4f43"]; - this[KeyboardEvent.DOM_VK_NUMPAD7] = ["1b4f48", "1b4f48"]; - this[KeyboardEvent.DOM_VK_NUMPAD8] = ["1b4f41", "1b4f41"]; - this[KeyboardEvent.DOM_VK_NUMPAD9] = ["1b5b357e", "1b5b357e"]; + this[97] = ["1b4f46", "1b4f46"]; + this[98] = ["1b4f42", "1b4f42"]; + this[99] = ["1b5b367e", "1b5b367e"]; + this[100] = ["1b4f44", "1b4f44"]; + this[101] = ["1b5b45", "1b5b45"]; + this[102] = ["1b4f43", "1b4f43"]; + this[103] = ["1b4f48", "1b4f48"]; + this[104] = ["1b4f41", "1b4f41"]; + this[105] = ["1b5b357e", "1b5b357e"]; return; } };