view termemu-keys.js @ 73:d084610a89b5

Automatically update the lists of current games and actions. Add some window.*interval() code to getcurrent() so it will register itself as an interval and clear this interval when the list is not visible (i.e. playing or watching.) It also calls getchoices() if the user is logged in, so that will be updated as well.
author John "Elwin" Edwards <elwin@sdf.org>
date Thu, 21 Jun 2012 21:57:04 -0700
parents d7eb63cd7a16
children 6cfaf6d202be
line wrap: on
line source

/* termemu-keys.js: some key-handling code common to both drivers. */

/* ASCII values of keys 0-9. */
var numShifts = [41, 33, 64, 35, 36, 37, 94, 38, 42, 40];

var keyHexCodes = {
  init: function () {
    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);
  },
  /* Multi-char control sequences!  Neat! */
  appCursor: function (on) {
    /* Aren't special keys vile? */
    if (on) {
      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[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) {
    /* In theory, these should produce either numerals or the k[a-c][1-3]
     * sequences.  Since we can't count on the terminfo description actually
     * containing those sequences, pretend they're just arrow keys etc.
     */
    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;
  }
};