comparison shterm.js @ 6:21738794755e

Put common key tables into a common file.
author John "Elwin" Edwards <elwin@sdf.org>
date Mon, 07 May 2012 13:08:24 -0700
parents e880f7589db5
children d1b3c3af34d6
comparison
equal deleted inserted replaced
5:e880f7589db5 6:21738794755e
172 datareq.open('POST', '/feed', true); 172 datareq.open('POST', '/feed', true);
173 datareq.send("keys=" + str); 173 datareq.send("keys=" + str);
174 return; 174 return;
175 } 175 }
176 176
177 /* ASCII values of keys 0-9. */
178 var numShifts = [41, 33, 64, 35, 36, 37, 94, 38, 42, 40];
179
180 var keyHexCodes = {
181 init: function () {
182 this[KeyboardEvent.DOM_VK_RETURN] = ["0d", "0d"];
183 this[KeyboardEvent.DOM_VK_SPACE] = ["20", "20"];
184 this[KeyboardEvent.DOM_VK_TAB] = ["09", "09"];
185 this[KeyboardEvent.DOM_VK_BACK_QUOTE] = ["60", "7e"];
186 this[KeyboardEvent.DOM_VK_OPEN_BRACKET] = ["5b", "7b"];
187 this[KeyboardEvent.DOM_VK_CLOSE_BRACKET] = ["5d", "7d"];
188 this[KeyboardEvent.DOM_VK_BACK_SLASH] = ["5c", "7c"];
189 this[KeyboardEvent.DOM_VK_SEMICOLON] = ["3b", "3a"];
190 this[KeyboardEvent.DOM_VK_QUOTE] = ["27", "22"];
191 this[KeyboardEvent.DOM_VK_COMMA] = ["2c", "3c"];
192 this[KeyboardEvent.DOM_VK_PERIOD] = ["2e", "3e"];
193 this[KeyboardEvent.DOM_VK_SLASH] = ["2f", "3f"];
194 this[KeyboardEvent.DOM_VK_EQUALS] = ["3d", "2b"];
195 this[KeyboardEvent.DOM_VK_SUBTRACT] = ["2d", "5f"];
196 this[KeyboardEvent.DOM_VK_BACK_SPACE] = ["08", "08"];
197 this[KeyboardEvent.DOM_VK_DELETE] = ["1b5b337e", "1b5b337e"];
198 this[KeyboardEvent.DOM_VK_ESCAPE] = ["1b", "1b"];
199 this[KeyboardEvent.DOM_VK_PAGE_UP] = ["1b5b357e", "1b5b357e"];
200 this[KeyboardEvent.DOM_VK_PAGE_DOWN] = ["1b5b367e", "1b5b367e"];
201 this.appCursor(false);
202 this.appKeypad(false);
203 },
204 /* Multi-char control sequences! Neat! */
205 appCursor: function (on) {
206 /* Aren't special keys vile? */
207 if (on) {
208 this[KeyboardEvent.DOM_VK_LEFT] = ["1b4f44", "1b4f44"];
209 this[KeyboardEvent.DOM_VK_RIGHT] = ["1b4f43", "1b4f43"];
210 this[KeyboardEvent.DOM_VK_UP] = ["1b4f41", "1b4f41"];
211 this[KeyboardEvent.DOM_VK_DOWN] = ["1b4f42", "1b4f42"];
212 this[KeyboardEvent.DOM_VK_END] = ["1b4f46", "1b4f46"];
213 this[KeyboardEvent.DOM_VK_HOME] = ["1b4f48", "1b4f48"];
214 }
215 else {
216 this[KeyboardEvent.DOM_VK_LEFT] = ["1b5b44", "1b5b44"];
217 this[KeyboardEvent.DOM_VK_RIGHT] = ["1b5b43", "1b5b43"];
218 this[KeyboardEvent.DOM_VK_UP] = ["1b5b41", "1b5b41"];
219 this[KeyboardEvent.DOM_VK_DOWN] = ["1b5b42", "1b5b42"];
220 this[KeyboardEvent.DOM_VK_END] = ["1b5b46", "1b5b46"];
221 this[KeyboardEvent.DOM_VK_HOME] = ["1b5b48", "1b5b48"];
222 }
223 },
224 appKeypad: function (on) {
225 /* In theory, these should produce either numerals or the k[a-c][1-3]
226 * sequences. Since we can't count on the terminfo description actually
227 * containing those sequences, pretend they're just arrow keys etc.
228 */
229 this[KeyboardEvent.DOM_VK_NUMPAD1] = ["1b4f46", "1b4f46"];
230 this[KeyboardEvent.DOM_VK_NUMPAD2] = ["1b4f42", "1b4f42"];
231 this[KeyboardEvent.DOM_VK_NUMPAD3] = ["1b5b367e", "1b5b367e"];
232 this[KeyboardEvent.DOM_VK_NUMPAD4] = ["1b4f44", "1b4f44"];
233 this[KeyboardEvent.DOM_VK_NUMPAD5] = ["1b5b45", "1b5b45"];
234 this[KeyboardEvent.DOM_VK_NUMPAD6] = ["1b4f43", "1b4f43"];
235 this[KeyboardEvent.DOM_VK_NUMPAD7] = ["1b4f48", "1b4f48"];
236 this[KeyboardEvent.DOM_VK_NUMPAD8] = ["1b4f41", "1b4f41"];
237 this[KeyboardEvent.DOM_VK_NUMPAD9] = ["1b5b357e", "1b5b357e"];
238 return;
239 }
240 };
241
242 function sendkey(ev) { 177 function sendkey(ev) {
243 var keynum = ev.keyCode; 178 var keynum = ev.keyCode;
244 var code; 179 var code;
245 if (keynum >= ev.DOM_VK_A && keynum <= ev.DOM_VK_Z) { 180 if (keynum >= ev.DOM_VK_A && keynum <= ev.DOM_VK_Z) {
246 /* Letters. This assumes the codes are 65-90. */ 181 /* Letters. This assumes the codes are 65-90. */