home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / microema.sit / src / keytrans_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-15  |  2.7 KB  |  129 lines  |  [TEXT/Earl]

  1. /*
  2.  * Keycode and Event Record interpreter for MicroEMACS 3.9e for the
  3.  * Macintosh.  This file is built into a separate code-containing
  4.  * resource of type GetC, ID #606.  It takes a pointer to an
  5.  * Event Record, and returns an appropriate eight-bit character
  6.  * code, ORed with one of four modifier flags, as below.
  7.  *
  8.  *    "This program supports ALL Macintosh keyboards."
  9.  *    (But YOU have to supply the key interpreter for YOUR keyboard!)
  10.  *
  11.  */
  12. #define __SEG__ Liberty
  13. #ifdef macintosh        /* MPW */
  14. #include <events.h>
  15. #else                    /* LSC */
  16. #include <EventMgr.h>
  17. #endif
  18. #define CTRL    0x0100        /* Control flag, or'ed in       */
  19. #define META    0x0200        /* Meta flag, or'ed in          */
  20. #define CTLX    0x0400        /* ^X flag, or'ed in            */
  21. #define SPEC    0x0800        /* special key (function key)    */
  22.  
  23. long main(E)
  24. EventRecord *E;
  25.  
  26. {
  27. unsigned short        c;
  28.  
  29. c = 0;
  30.  
  31.         switch ( (E->message&keyCodeMask)>>8 ){
  32. /*
  33.  * Extended Keyboard Function Keys.
  34.  */
  35.             case 122:
  36.                 c = SPEC | '1';    /* Saratoga "F1" */
  37.                 break;
  38.             case 120:
  39.                 c = SPEC | '2';
  40.                 break;
  41.             case 99:
  42.                 c = SPEC | '3';
  43.                 break;
  44.             case 118:
  45.                 c = SPEC | '4';
  46.                 break;
  47.             case 96:
  48.                 c = SPEC | '5';
  49.                 break;
  50.             case 97:
  51.                 c = SPEC | '6';
  52.                 break;
  53.             case 98:
  54.                 c = SPEC | '7';
  55.                 break;
  56.             case 100:
  57.                 c = SPEC | '8';
  58.                 break;
  59.             case 101:
  60.                 c = SPEC | '9';
  61.                 break;
  62.             case 109:
  63.                 c = SPEC | 'A';
  64.                 break;
  65.             case 103:
  66.                 c = SPEC | 'B';
  67.                 break;
  68.             case 111:
  69.                 c = SPEC | 'C';
  70.                 break;
  71.             case 105:
  72.                 c = SPEC | 'D';
  73.                 break;
  74.             case 107:
  75.                 c = SPEC | 'E';
  76.                 break;
  77.             case 113:
  78.                 c = SPEC | 'F';    /* "F15" */
  79.                 break;
  80. /*
  81.  * Special Keys.
  82.  */
  83.             case 121:        /* Page Down */
  84.                 c = SPEC | 'V';
  85.                 break;
  86.             case 116:        /* Page Up */
  87.                 c = SPEC | 'Z';
  88.                 break;
  89.             case 119:        /* End */
  90.                 c = SPEC | '>';
  91.                 break;
  92.             case 115:        /* Home */
  93.                 c = SPEC | '<';
  94.                 break;
  95.             case 114:        /* Help */
  96.                 c = SPEC | '?';
  97.                 break;
  98.             case 117:        /* Del */
  99.                 return (127);
  100.             default:
  101.                 break;
  102.         }
  103.     if (c != 0)return c;
  104.  
  105.     /* Get the character code. */
  106.  
  107.     c =   (unsigned short)  (E->message & charCodeMask);
  108. /*
  109.  * Map control characters to their positions.  Pre-ADB keyboards
  110.  * use the propeller key for control.  Propeller-digit is used to
  111.  * emulate function keys f1 through f10 and F1 through F10.
  112.  * The normal 32 control characters can be generated with the
  113.  * command key, as well as some bogus ones, like ^╢, ^;, and
  114.  * lots others.
  115.  */
  116.     if(E->modifiers & cmdKey){
  117.         if( c <= '9' && c >= '0'){
  118.             return (c | SPEC);
  119.         }
  120.         if ( c == '[' || c == ']' || c == '^' || c == '_' || c == '\\'
  121.           || c <= ' ' || ( c >= 'A' && c <= 'Z')
  122.             || ( c >= 'a' && c <= 'z'))
  123.             c &= 31;
  124.         else c |= CTRL;
  125.     }
  126.     return (c);
  127. }
  128.  
  129.