Back to index

plt-scheme  4.2.1
pc_keys.inc
Go to the documentation of this file.
00001 
00002 /* Standard U.S. keyboard (sorry, world). */
00003 /* Started with OSKit code, but I wanted more keys, including Ctl-C */
00004 
00005 #define SHIFT -1
00006 #define CTL -2
00007 #define ALT -3
00008 
00009 static int shift_state, ctl_state, alt_state;
00010 
00011 static char keymap[128][2] = {
00012        {0,     0},             /* 0 */
00013        {27,   27},          /* 1 - ESC */
00014        {'1',  '!'},         /* 2 */
00015        {'2',  '@'},
00016        {'3',  '#'},
00017        {'4',  '$'},
00018        {'5',  '%'},
00019        {'6',  '^'},
00020        {'7',  '&'},
00021        {'8',  '*'},
00022        {'9',  '('},
00023        {'0',  ')'},
00024        {'-',  '_'},
00025        {'=',  '+'},
00026        {8,    8},           /* 14 - Backspace */
00027        {'\t', '\t'},        /* 15 */
00028        {'q',  'Q'},
00029        {'w',  'W'},
00030        {'e',  'E'},
00031        {'r',  'R'},
00032        {'t',  'T'},
00033        {'y',  'Y'},
00034        {'u',  'U'},
00035        {'i',  'I'},
00036        {'o',  'O'},
00037        {'p',  'P'},
00038        {'[',  '{'},
00039        {']',  '}'},         /* 27 */
00040        {'\r', '\r'},        /* 28 - Enter */
00041        {CTL,  CTL},         /* 29 - Ctrl */
00042        {'a',  'A'},         /* 30 */
00043        {'s',  'S'},
00044        {'d',  'D'},
00045        {'f',  'F'},
00046        {'g',  'G'},
00047        {'h',  'H'},
00048        {'j',  'J'},
00049        {'k',  'K'},
00050        {'l',  'L'},
00051        {';',  ':'},
00052        {'\'', '"'},         /* 40 */
00053        {'`',  '~'},         /* 41 */
00054        {SHIFT,       SHIFT},              /* 42 - Left Shift */
00055        {'\\', '|'},         /* 43 */
00056        {'z',  'Z'},         /* 44 */
00057        {'x',  'X'},
00058        {'c',  'C'},
00059        {'v',  'V'},
00060        {'b',  'B'},
00061        {'n',  'N'},
00062        {'m',  'M'},
00063        {',',  '<'},
00064        {'.',  '>'},
00065        {'/',  '?'},         /* 53 */
00066        {SHIFT,       SHIFT},              /* 54 - Right Shift */
00067        {0,    0},           /* 55 - Print Screen */
00068        {ALT,  ALT},         /* 56 - Alt */
00069        {' ',  ' '},         /* 57 - Space bar */
00070        {0,    0},           /* 58 - Caps Lock */
00071        {0,    0},           /* 59 - F1 */
00072        {0,    0},           /* 60 - F2 */
00073        {0,    0},           /* 61 - F3 */
00074        {0,    0},           /* 62 - F4 */
00075        {0,    0},           /* 63 - F5 */
00076        {0,    0},           /* 64 - F6 */
00077        {0,    0},           /* 65 - F7 */
00078        {0,    0},           /* 66 - F8 */
00079        {0,    0},           /* 67 - F9 */
00080        {0,    0},           /* 68 - F10 */
00081        {0,    0},           /* 69 - Num Lock */
00082        {0,    0},           /* 70 - Scroll Lock */
00083        {'7',  '7'},         /* 71 - Numeric keypad 7 */
00084        {'8',  '8'},         /* 72 - Numeric keypad 8 */
00085        {'9',  '9'},         /* 73 - Numeric keypad 9 */
00086        {'-',  '-'},         /* 74 - Numeric keypad '-' */
00087        {'4',  '4'},         /* 75 - Numeric keypad 4 */
00088        {'5',  '5'},         /* 76 - Numeric keypad 5 */
00089        {'6',  '6'},         /* 77 - Numeric keypad 6 */
00090        {'+',  '+'},         /* 78 - Numeric keypad '+' */
00091        {'1',  '1'},         /* 79 - Numeric keypad 1 */
00092        {'2',  '2'},         /* 80 - Numeric keypad 2 */
00093        {'3',  '3'},         /* 81 - Numeric keypad 3 */
00094        {'0',  '0'},         /* 82 - Numeric keypad 0 */
00095        {'.',  '.'},         /* 83 - Numeric keypad '.' */
00096 };
00097 
00098 int convert_scan_code(int k)
00099 {
00100   if (k & 0x80) {
00101     /* Key release. Look for modifier releases. */
00102     k &= 0x7f;
00103     k = keymap[k][0];
00104     if (k == SHIFT)
00105       shift_state = 0;
00106     else if (k == CTL)
00107       ctl_state = 0;
00108     else if (k == ALT)
00109       alt_state = 0;
00110     return -1;
00111   } else {
00112     /* Translate the character through the keymap. */
00113     k = keymap[k][shift_state];
00114     if (k == SHIFT)
00115       shift_state = 1;
00116     else if (k == CTL)
00117       ctl_state = 1;
00118     else if (k == ALT)
00119       alt_state = 1;
00120     else {
00121       if (k == '.') {
00122        /* Check for Ctl-Alt-Del */
00123        if (ctl_state && alt_state)
00124          exit(0);
00125       }
00126 
00127       if (ctl_state) {
00128        if (('A' <= k) && (k <= 'Z'))
00129          k += ('a' - 'A');
00130        
00131        if (('a' <= k) && (k <= 'z'))
00132          k -= ('a' - 1);
00133        else
00134          k = -1;
00135       }
00136       
00137       return k;
00138     }
00139 
00140     return -1;
00141   }
00142 }
00143 
00144 #undef SHIFT
00145 #undef CTL
00146 #undef ALT