annotate termemu-keys.js @ 35:f15efa4818b4

rglterm.js: reduce the server polling. For roguelike games, most output will directly result from and follow immediately after input from the user. In other situations, data should not be expected.
author John "Elwin" Edwards <elwin@sdf.org>
date Tue, 05 Jun 2012 22:33:41 -0700
parents 21738794755e
children d7eb63cd7a16
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
1 /* termemu-keys.js: some key-handling code common to both drivers. */
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
2
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
3 /* ASCII values of keys 0-9. */
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
4 var numShifts = [41, 33, 64, 35, 36, 37, 94, 38, 42, 40];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
5
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
6 var keyHexCodes = {
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
7 init: function () {
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
8 this[KeyboardEvent.DOM_VK_RETURN] = ["0d", "0d"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
9 this[KeyboardEvent.DOM_VK_SPACE] = ["20", "20"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
10 this[KeyboardEvent.DOM_VK_TAB] = ["09", "09"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
11 this[KeyboardEvent.DOM_VK_BACK_QUOTE] = ["60", "7e"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
12 this[KeyboardEvent.DOM_VK_OPEN_BRACKET] = ["5b", "7b"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
13 this[KeyboardEvent.DOM_VK_CLOSE_BRACKET] = ["5d", "7d"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
14 this[KeyboardEvent.DOM_VK_BACK_SLASH] = ["5c", "7c"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
15 this[KeyboardEvent.DOM_VK_SEMICOLON] = ["3b", "3a"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
16 this[KeyboardEvent.DOM_VK_QUOTE] = ["27", "22"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
17 this[KeyboardEvent.DOM_VK_COMMA] = ["2c", "3c"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
18 this[KeyboardEvent.DOM_VK_PERIOD] = ["2e", "3e"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
19 this[KeyboardEvent.DOM_VK_SLASH] = ["2f", "3f"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
20 this[KeyboardEvent.DOM_VK_EQUALS] = ["3d", "2b"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
21 this[KeyboardEvent.DOM_VK_SUBTRACT] = ["2d", "5f"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
22 this[KeyboardEvent.DOM_VK_BACK_SPACE] = ["08", "08"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
23 this[KeyboardEvent.DOM_VK_DELETE] = ["1b5b337e", "1b5b337e"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
24 this[KeyboardEvent.DOM_VK_ESCAPE] = ["1b", "1b"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
25 this[KeyboardEvent.DOM_VK_PAGE_UP] = ["1b5b357e", "1b5b357e"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
26 this[KeyboardEvent.DOM_VK_PAGE_DOWN] = ["1b5b367e", "1b5b367e"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
27 this.appCursor(false);
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
28 this.appKeypad(false);
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
29 },
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
30 /* Multi-char control sequences! Neat! */
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
31 appCursor: function (on) {
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
32 /* Aren't special keys vile? */
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
33 if (on) {
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
34 this[KeyboardEvent.DOM_VK_LEFT] = ["1b4f44", "1b4f44"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
35 this[KeyboardEvent.DOM_VK_RIGHT] = ["1b4f43", "1b4f43"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
36 this[KeyboardEvent.DOM_VK_UP] = ["1b4f41", "1b4f41"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
37 this[KeyboardEvent.DOM_VK_DOWN] = ["1b4f42", "1b4f42"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
38 this[KeyboardEvent.DOM_VK_END] = ["1b4f46", "1b4f46"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
39 this[KeyboardEvent.DOM_VK_HOME] = ["1b4f48", "1b4f48"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
40 }
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
41 else {
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
42 this[KeyboardEvent.DOM_VK_LEFT] = ["1b5b44", "1b5b44"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
43 this[KeyboardEvent.DOM_VK_RIGHT] = ["1b5b43", "1b5b43"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
44 this[KeyboardEvent.DOM_VK_UP] = ["1b5b41", "1b5b41"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
45 this[KeyboardEvent.DOM_VK_DOWN] = ["1b5b42", "1b5b42"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
46 this[KeyboardEvent.DOM_VK_END] = ["1b5b46", "1b5b46"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
47 this[KeyboardEvent.DOM_VK_HOME] = ["1b5b48", "1b5b48"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
48 }
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
49 },
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
50 appKeypad: function (on) {
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
51 /* In theory, these should produce either numerals or the k[a-c][1-3]
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
52 * sequences. Since we can't count on the terminfo description actually
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
53 * containing those sequences, pretend they're just arrow keys etc.
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
54 */
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
55 this[KeyboardEvent.DOM_VK_NUMPAD1] = ["1b4f46", "1b4f46"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
56 this[KeyboardEvent.DOM_VK_NUMPAD2] = ["1b4f42", "1b4f42"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
57 this[KeyboardEvent.DOM_VK_NUMPAD3] = ["1b5b367e", "1b5b367e"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
58 this[KeyboardEvent.DOM_VK_NUMPAD4] = ["1b4f44", "1b4f44"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
59 this[KeyboardEvent.DOM_VK_NUMPAD5] = ["1b5b45", "1b5b45"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
60 this[KeyboardEvent.DOM_VK_NUMPAD6] = ["1b4f43", "1b4f43"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
61 this[KeyboardEvent.DOM_VK_NUMPAD7] = ["1b4f48", "1b4f48"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
62 this[KeyboardEvent.DOM_VK_NUMPAD8] = ["1b4f41", "1b4f41"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
63 this[KeyboardEvent.DOM_VK_NUMPAD9] = ["1b5b357e", "1b5b357e"];
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
64 return;
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
65 }
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
66 };
21738794755e Put common key tables into a common file.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
67