home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34exe.zip / me / misc / os2kmap.c < prev   
C/C++ Source or Header  |  1995-01-14  |  8KB  |  212 lines

  1. /*
  2.  * pckmap.c MODULE: ibm pc key mapping
  3.  * C Durland    Public Domain
  4.  * John Burnell Added support for grey keypad 3/92
  5.  * John Burnell Added more support for grey keypad 5/92
  6.  * Patrick McPhee Added OS/2 changes
  7.  */
  8. #include "me2.h"
  9. #include "term.h"
  10.  
  11. static char what[] = "@(#)PC Keymap";
  12.  
  13. typedef struct { unsigned int scancode; EKeyCode keycode; } PCKeyMap;
  14.  
  15.     /* The cursor pad between the number pad and the rest of the keyboard.
  16.      */
  17. static PCKeyMap old_key_map[] =
  18.   {
  19.     0x0047, SOFKEY|'A',        /* Home */
  20.     0x004F, SOFKEY|'B',        /* End */
  21.     0x0048, SOFKEY|'C',        /* Up Arrow */
  22.     0x0050, SOFKEY|'D',        /* Down Arrow */
  23.     0x004D, SOFKEY|'E',        /* Right Arrow */
  24.     0x004B, SOFKEY|'F',        /* Left Arrow */
  25.     0x0053, SOFKEY|'H',        /* Delete */
  26.     0x0052, SOFKEY|'G',        /* Insert */
  27.     0x0051, SOFKEY|'J',        /* Page Down */
  28.     0x0049, SOFKEY|'I',        /* Page Up */
  29.  
  30.     0x0077, SOFKEY|'A' |CTRL,    /* Control Home */
  31.     0x0075, SOFKEY|'B' |CTRL,    /* Control End */
  32.     0x008d, SOFKEY|'C' |CTRL,    /* Up Arrow */
  33.     0x0091, SOFKEY|'D' |CTRL,    /* Down Arrow */
  34.     0x0074, SOFKEY|'E' |CTRL,    /* Right Arrow */
  35.     0x0073, SOFKEY|'F' |CTRL,    /* Left Arrow */
  36.     0x0093, SOFKEY|'H' |CTRL,    /* Delete */
  37.     0x0092, SOFKEY|'G' |CTRL,    /* Insert */
  38.     0x0076, SOFKEY|'J' |CTRL,   /* Control Page Down */
  39.     0x0084, SOFKEY|'I' |CTRL,   /* Control Page Up */
  40.  
  41.     0    /* end of table */
  42.   };
  43.  
  44. static PCKeyMap extended_key_map[] =
  45.   {
  46.     0x0003,  '\0',        /* Control @ */
  47.  
  48.     /* and now a few ALT mappings */
  49.     0x0081, META|'0', /* '0' not in ascii order. 1..9 mapped in map_key() */
  50.     0x0078, META|'!',
  51.     0x001E, META|'A',
  52.     0x0030, META|'B',
  53.     0x002E, META|'C',
  54.     0x0020, META|'D',
  55.     0x0012, META|'E',
  56.     0x0021, META|'F',
  57.     0x0022, META|'G',
  58.     0x0023, META|'H',
  59.     0x0017, META|'I',
  60.     0x000F, META|'I',        /* shift tab */
  61.     0x0024, META|'J',
  62.     0x0025, META|'K',
  63.     0x0026, META|'L',
  64.     0x0032, META|'M',
  65.     0x0031, META|'N',
  66.     0x0018, META|'O',
  67.     0x0019, META|'P',
  68.     0x0010, META|'Q',
  69.     0x0013, META|'R',
  70.     0x001F, META|'S',
  71.     0x0014, META|'T',
  72.     0x0016, META|'U',
  73.     0x002F, META|'V',
  74.     0x0011, META|'W',
  75.     0x002D, META|'X',
  76.     0x0015, META|'Y',
  77.     0x002C, META|'Z',
  78.  
  79.     0x0044,      SOFKEY|'0',    /* F10 */
  80.     0x005D, SHIFT|SOFKEY|'0',    /* Shift F10 */
  81.     0x0067, CTRL |SOFKEY|'0',    /* Control F10 */
  82.     0x0071, META |SOFKEY|'0',    /* Alt F10 */
  83.  
  84.     0x0001, META|CTRL|'[',    /* Alt ESC */
  85.     0x000E, META|CTRL|'H',    /* Alt backspace */
  86.     0x00A5, META|CTRL|'I',    /* Alt tab */
  87.     0x001C, META|CTRL|'M',    /* Alt enter */
  88.     0x0027, META|';',        /* Alt ; */
  89.     0x0028, META|'\'',        /* Alt ' */
  90.     0x0029, META|'`',        /* Alt ` */
  91.     0x002B, META|'\\',        /* Alt \ */
  92.     0x0033, META|',',        /* Alt , */
  93.     0x0034, META|'.',        /* Alt . */
  94.     0x0035, META|'/',        /* Alt / */
  95.     0x0085,      SOFKEY|'a',    /* F11 */
  96.     0x0087, SHIFT|SOFKEY|'a',    /* Shift   F11 */
  97.     0x0089, CTRL |SOFKEY|'a',    /* Control F11 */
  98.     0x008B, META |SOFKEY|'a',    /* Alt     F11 */
  99.     0x0086,      SOFKEY|'b',    /* F12 */
  100.     0x0088, SHIFT|SOFKEY|'b',    /* Shift   F12 */
  101.     0x008A, CTRL |SOFKEY|'b',    /* Control F12 */
  102.     0x008C, META |SOFKEY|'b',    /* Alt     F12 */
  103.  
  104.     0x004C, SOFKEY|'c',        /* middle of cursor pad (5) */
  105.     0x008F, CTRL|SOFKEY|'c',     /* ALT middle of cursor pad (5) */
  106.  
  107.     0xE047,      SOFKEY|'A',    /* Cursor pad Home */
  108.     0xE04F,      SOFKEY|'B',    /* Cursor pad End */
  109.     0xE048,      SOFKEY|'C',    /* Cursor pad Cursor Up */
  110.     0xE050,      SOFKEY|'D',    /* Cursor pad Cursor Down */
  111.     0xE04D,      SOFKEY|'E',    /* Cursor pad Cursor Right */
  112.     0xE04B,      SOFKEY|'F',    /* Cursor pad Cursor Left */
  113.     0xE052,      SOFKEY|'G',    /* Cursor pad Insert */
  114.     0xE053,      SOFKEY|'H',    /* Cursor pad Delete */
  115.     0xE049,      SOFKEY|'I',    /* Cursor pad Page Up */
  116.     0xE051,      SOFKEY|'J',    /* Cursor pad Page Down */
  117.     0xE077, CTRL |SOFKEY|'A',    /* Cursor pad Control Home */
  118.     0xE075, CTRL |SOFKEY|'B',    /* Cursor pad Control End */
  119.     0xE08D, CTRL |SOFKEY|'C',    /* Cursor pad Control Up Arrow */
  120.     0xE091, CTRL |SOFKEY|'D',    /* Cursor pad Control Down Arrow */
  121.     0xE074, CTRL |SOFKEY|'E',    /* Cursor pad Control Right Arrow */
  122.     0xE073, CTRL |SOFKEY|'F',    /* Cursor pad Control Left Arrow */
  123.     0xE092, CTRL |SOFKEY|'G',    /* Cursor pad Control Insert */
  124.     0xE093, CTRL |SOFKEY|'H',    /* Cursor pad control Delete */
  125.     0xE084, CTRL |SOFKEY|'I',    /* Cursor pad control Page Up */
  126.     0xE076, CTRL |SOFKEY|'J',    /* Cursor pad control Page Down */
  127.  
  128.     0x0047, SOFKEY|'{',        /* Number pad Home */
  129.     0x004F, SOFKEY|'}',        /* Number pad End */
  130.     0x0049, SOFKEY|'[',        /* Number pad Page Up */
  131.     0x0051, SOFKEY|']',        /* Number pad Page Down */
  132.     0x0048, SOFKEY|'^',        /* Number pad Up Arrow */
  133.     0x0050, SOFKEY|'.',        /* Number pad Down Arrow */
  134.     0x004D, SOFKEY|'>',        /* Number pad Right Arrow */
  135.     0x004B, SOFKEY|'<',        /* Number pad Left Arrow */
  136.     0x0052, SOFKEY|'&',        /* Number pad Insert */
  137.     0x0053, SOFKEY|'#',        /* Number pad Delete */
  138.  
  139.     0xE00D, SOFKEY|'$',        /* Number pad Enter */
  140.     0xE02A, SOFKEY|'*',        /* Number pad *  */
  141.     0xE02B, SOFKEY|'+',        /* Number pad +  */
  142.     0xE02D, SOFKEY|'-',        /* Number pad -  */
  143.     0xE02F, SOFKEY|'/',        /* Number pad /  */
  144.  
  145.     0x0077, SOFKEY|'{' |CTRL,    /* Number pad Control Home */
  146.     0x0075, SOFKEY|'}' |CTRL,    /* Number pad Control End */
  147.     0x0084, SOFKEY|'[' |CTRL,    /* Number pad Control Page Up */
  148.     0x0076, SOFKEY|']' |CTRL,    /* Number pad Control Page Down */
  149.     0x008D, SOFKEY|'^' |CTRL,    /* Number pad Control Up Arrow */
  150.     0x0091, SOFKEY|'.' |CTRL,    /* Number pad Control Down Arrow */
  151.     0x0074, SOFKEY|'>' |CTRL,    /* Number pad Control Right Arrow */
  152.     0x0073, SOFKEY|'<' |CTRL,    /* Number pad Control Left Arrow */
  153.     0x0092, SOFKEY|'&' |CTRL,    /* Number pad Control Insert */
  154.     0x0093, SOFKEY|'#' |CTRL,    /* Number pad Control Delete */
  155.  
  156.     0    /* end of table */
  157.   };
  158.  
  159. static int look_for_key(key_map, scancode, keycode)
  160.   PCKeyMap *key_map; unsigned int scancode; EKeyCode *keycode;
  161. {
  162.   for (; key_map->scancode; key_map++)
  163.     if (key_map->scancode == scancode)  /* found it */
  164.     { *keycode = key_map->keycode; return TRUE; }
  165.  
  166.   return FALSE;
  167. }
  168.  
  169.     /* Convert terminal codes to ME codes.
  170.      * Input:
  171.      *   scancode:  The scan code returned from Kbd fns.  Normally just a
  172.      *     byte but can be 2 bytes (for example with some of the Cursor pad
  173.      *     (grey on the extended keyboard) keypad keys).
  174.      *   keycode:  pointer to a EKeyCode that hold the converted key.
  175.      * Changes: *keycode
  176.      * Returns:
  177.      *   TRUE:  Everything went as expected.
  178.      *   FALSE: Unreconized scancode.
  179.      */
  180. map_key(scancode, keycode)
  181.   unsigned int scancode; EKeyCode *keycode;
  182. {
  183.   /* ************* Function keys ************************************ */
  184.   /* Convert Function key 1..9 to SOFKEY 1...9 */
  185.   if (0x3B <= scancode && scancode <= 0x43)
  186.     { *keycode = SOFKEY | (scancode - 0xA); return TRUE; }
  187.  
  188.      /* Convert Shift Function key 1..9 to SHIFT SOFKEY 1...9 */
  189.   if (0x54 <= scancode && scancode <= 0x5C)
  190.     { *keycode = SHIFT |  SOFKEY | (scancode - 0x23); return TRUE; }
  191.  
  192.      /* Convert Control Function key 1..9 to CTRL SOFKEY 1...9 */
  193.   if (0x5E <= scancode && scancode <= 0x66)
  194.     { *keycode = CTRL | SOFKEY | (scancode - 0x2D); return TRUE; }
  195.  
  196.      /* Convert Alt Function key 1..9 to META SOFKEY 1...9 */
  197.   if (0x68 <= scancode && scancode <= 0x70)
  198.     { *keycode = META | SOFKEY | (scancode - 0x37); return TRUE; }
  199.  
  200.     /* ************* Alt keys ************************************ */
  201.             /* convert Alt 1...9 to META "1"..."9" */
  202.   if (0x78 <= scancode && scancode <= 0x80)
  203.     { *keycode = META | (scancode - 0x47); return TRUE; }
  204.  
  205.  
  206.     /* ************* Everybody else ********************************* */
  207.   if (look_for_key(old_key_map,         scancode, keycode)) return TRUE;
  208.   if (look_for_key(extended_key_map, scancode, keycode)) return TRUE;
  209.  
  210.   return FALSE;                          /* not found */
  211. }
  212.