home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / UE311C.ZIP / KEYBOARD.C < prev    next >
C/C++ Source or Header  |  1991-09-23  |  8KB  |  226 lines

  1. /*===========================================================================
  2.  
  3.         KEYBOARD.C for MSDOS and OS/2
  4.  
  5.         extcode()
  6.  
  7.         This routine is common to the MSDOS and OS/2 implementations.
  8.         It is used to resolve extended character codes from the keyboard
  9.         into EMACS printable character specifications.
  10.  
  11.         This implementation can handle the extended AT-style keyboard
  12.         if one is fitted.
  13.  
  14.         I don't know what happens on an XT but I suspect that it should
  15.         work as if there were no extended keys.
  16.  
  17.                                 Jon Saxton
  18.                                 24 Jan 1990
  19.  
  20. ===========================================================================*/  
  21.  
  22. #include    <stdio.h>
  23. #include    "estruct.h"
  24. #include    "eproto.h"
  25. #include    "edef.h"
  26. #include    "elang.h"
  27.  
  28. #if MSDOS | OS2
  29. #if HP150 == 0
  30.  
  31. int extcode(c)
  32.  
  33. unsigned c;    /* byte following a zero extended char byte */
  34.         /* High order normally contains 0x00 but may
  35.            contain 0xE0 if an AT-style keyboard is attached */
  36. {
  37.     /* function keys 1 through 9.  High-order will be 0x00 */
  38.     if (c >= 0x3B && c < 0x44)
  39.         return(SPEC | c - 0x3A + '0');
  40.  
  41.     /* function key 10 */
  42.     if (c == 0x44)
  43.         return(SPEC | '0');
  44.  
  45.     /* shifted function keys */
  46.     if (c >= 0x54 && c < 0x5D)
  47.         return(SPEC | SHFT | c - 0x53 + '0');
  48.     if (c == 0x5D)
  49.         return(SPEC | SHFT | '0');
  50.  
  51.     /* control function keys */
  52.     if (c >= 0x5E && c < 0x67)
  53.         return(SPEC | CTRL | c - 0x5D + '0');
  54.     if (c == 0x67)
  55.         return(SPEC | CTRL | '0');
  56.  
  57.     /* ALTed function keys */
  58.     if (c >= 0x68 && c < 0x71)
  59.         return(SPEC | ALTD | c - 0x67 + '0');
  60.     if (c == 0x71)
  61.         return(SPEC | ALTD | '0');
  62.  
  63.     /* ALTed number keys */
  64.     /* This doesn't work for DOS or OS/2.  Using ALT in conjunction with
  65.        the number keys lets you enter any (decimal) character value
  66.        you want.  It is therefore commented out.
  67.  
  68.        Wrongo joker... alting the top row of numbers works fine DML */
  69.     if (c >= 0x78 && c < 0x81)
  70.         return(ALTD | c - 0x77 + '0');
  71.     if (c == 0x81)
  72.         return(ALTD | '0');
  73.  
  74.     /* some others as well */
  75.     switch (c) {
  76.  
  77. case 3:        return(0);            /* null */
  78. case 0x0F:    return(SHFT | CTRL | 'I');    /* backtab */
  79.  
  80. case 0x10:    return(ALTD | 'Q');
  81. case 0x11:    return(ALTD | 'W');
  82. case 0x12:    return(ALTD | 'E');
  83. case 0x13:    return(ALTD | 'R');
  84. case 0x14:    return(ALTD | 'T');
  85. case 0x15:    return(ALTD | 'Y');
  86. case 0x16:    return(ALTD | 'U');
  87. case 0x17:    return(ALTD | 'I');
  88. case 0x18:    return(ALTD | 'O');
  89. case 0x19:    return(ALTD | 'P');
  90.  
  91. case 0x1E:    return(ALTD | 'A');
  92. case 0x1F:    return(ALTD | 'S');
  93. case 0x20:    return(ALTD | 'D');
  94. case 0x21:    return(ALTD | 'F');
  95. case 0x22:    return(ALTD | 'G');
  96. case 0x23:    return(ALTD | 'H');
  97. case 0x24:    return(ALTD | 'J');
  98. case 0x25:    return(ALTD | 'K');
  99. case 0x26:    return(ALTD | 'L');
  100.  
  101. case 0x2C:    return(ALTD | 'Z');
  102. case 0x2D:    return(ALTD | 'X');
  103. case 0x2E:    return(ALTD | 'C');
  104. case 0x2F:    return(ALTD | 'V');
  105. case 0x30:    return(ALTD | 'B');
  106. case 0x31:    return(ALTD | 'N');
  107. case 0x32:    return(ALTD | 'M');
  108.  
  109. case 0x47:    return(SPEC | '<');    /* home */
  110. case 0x48:    return(SPEC | 'P');    /* cursor up */
  111. case 0x49:    return(SPEC | 'Z');    /* page up */
  112. case 0x4B:    return(SPEC | 'B');    /* cursor left */
  113. case 0x4C:    return(SPEC | 'L');    /* NP 5 */
  114. case 0x4D:    return(SPEC | 'F');    /* cursor right */
  115. case 0x4F:    return(SPEC | '>');    /* end */
  116. case 0x50:    return(SPEC | 'N');    /* cursor down */
  117. case 0x51:    return(SPEC | 'V');    /* page down */
  118. case 0x52:    return(SPEC | 'C');    /* insert */
  119. case 0x53:    return(SPEC | 'D');    /* delete */
  120.  
  121. case 0x73:    return(SPEC | CTRL | 'B');    /* control left */
  122. case 0x74:    return(SPEC | CTRL | 'F');    /* control right */
  123. case 0x75:    return(SPEC | CTRL | '>');    /* control end */
  124. case 0x76:    return(SPEC | CTRL | 'V');    /* control page down */
  125. case 0x77:    return(SPEC | CTRL | '<');    /* control home */
  126. case 0x84:    return(SPEC | CTRL | 'Z');    /* control page up */
  127. case 0x8D:    return(SPEC | CTRL | 'P');    /* control up */
  128. case 0x8F:    return(SPEC | CTRL | 'L');    /* control NP5 */
  129. case 0x91:    return(SPEC | CTRL | 'N');    /* control down */
  130. case 0x92:    return(SPEC | CTRL | 'C');    /* control grey insert */
  131. case 0x93:    return(SPEC | CTRL | 'D');    /* control grey delete */
  132.  
  133. case 0x82:    return(ALTD | '-');    /* alt - */
  134. case 0x83:    return(ALTD | '=');    /* alt = */
  135. case 0x27:    return(ALTD | ';');    /* alt ; */
  136. case 0x28:    return(ALTD | '\'');    /* alt ' */
  137. case 0x2B:    return(ALTD | '\\');    /* alt \ */
  138. case 0x1A:    return(ALTD | '[');    /* alt [ */
  139. case 0x1B:    return(ALTD | ']');    /* alt ] */
  140.  
  141. #if ATKBD | OS2
  142.  
  143. /* F11 and F12 */
  144.  
  145. case 0x85:    return(SPEC | '-');         /* F11 */
  146. case 0x86:    return(SPEC | '=');        /* F12 */
  147. case 0x87:    return(SPEC | SHFT | '-');    /* shift F11 */
  148. case 0x88:    return(SPEC | SHFT | '=');    /* shift F12 */
  149. case 0x89:    return(SPEC | CTRL | '-');    /* control F11 */
  150. case 0x8A:    return(SPEC | CTRL | '=');    /* control F12 */
  151. case 0x8B:    return(SPEC | ALTD | '-');    /* alt F11 */
  152. case 0x8C:    return(SPEC | ALTD | '=');    /* alt F12 */
  153.  
  154. /*
  155.    This implementation distinguishes between the cursor controls on the
  156.    number pad and those on the grey keypad if an AT-style keyboard is
  157.    fitted.
  158. */ 
  159.  
  160. case 0xE047:    return(SPEC | 'a');        /* grey home */
  161. case 0xE048:    return(SPEC | 'b');        /* grey cursor up */
  162. case 0xE049:    return(SPEC | 'c');        /* grey page up */
  163. case 0xE04B:    return(SPEC | 'd');        /* grey cursor left */
  164. case 0xE04C:    return(SPEC | 'e');        /* grey center key */
  165. case 0xE04D:    return(SPEC | 'f');        /* grey cursor right */
  166. case 0xE04F:    return(SPEC | 'g');        /* grey end */
  167. case 0xE050:    return(SPEC | 'h');        /* grey cursor down */
  168. case 0xE051:    return(SPEC | 'i');        /* grey page down */
  169. case 0xE052:    return(SPEC | 'j');        /* grey insert */
  170. case 0xE053:    return(SPEC | 'k');        /* grey delete */
  171.  
  172. case 0xE077:    return(SPEC | CTRL | 'a');    /* control grey home */
  173. case 0xE08D:    return(SPEC | CTRL | 'b');    /* control grey up */
  174. case 0xE084:    return(SPEC | CTRL | 'c');    /* control grey page up */
  175. case 0xE073:    return(SPEC | CTRL | 'd');    /* control grey left */
  176. case 0xE074:    return(SPEC | CTRL | 'f');    /* control grey right */
  177. case 0xE075:    return(SPEC | CTRL | 'g');    /* control grey end */
  178. case 0xE091:    return(SPEC | CTRL | 'h');    /* control grey down */
  179. case 0xE076:    return(SPEC | CTRL | 'i');    /* control grey page down */
  180. case 0xE092:    return(SPEC | CTRL | 'j');    /* control grey insert */
  181. case 0xE093:    return(SPEC | CTRL | 'k');    /* control grey delete */
  182.  
  183. case 0xE097:    return(SPEC | ALTD | 'a');    /* alt grey home */
  184. case 0xE098:    return(SPEC | ALTD | 'b');    /* alt grey cursor up */
  185. case 0xE099:    return(SPEC | ALTD | 'c');    /* alt grey page up */
  186. case 0xE09B:    return(SPEC | ALTD | 'd');    /* alt grey cursor left */
  187. case 0xE09D:    return(SPEC | ALTD | 'f');    /* alt grey cursor right */
  188. case 0xE09F:    return(SPEC | ALTD | 'g');    /* alt grey end */
  189. case 0xE0A0:    return(SPEC | ALTD | 'h');    /* alt grey cursor down */
  190. case 0xE0A1:    return(SPEC | ALTD | 'i');    /* alt grey page down */
  191. case 0xE0A2:    return(SPEC | ALTD | 'j');    /* alt grey insert */
  192. case 0xE0A3:    return(SPEC | ALTD | 'k');    /* alt grey delete */
  193.  
  194. case 0x97:    return(SPEC | ALTD | 'a');    /* alt grey home */
  195. case 0x98:    return(SPEC | ALTD | 'b');    /* alt grey cursor up */
  196. case 0x99:    return(SPEC | ALTD | 'c');    /* alt grey page up */
  197. case 0x9B:    return(SPEC | ALTD | 'd');    /* alt grey cursor left */
  198. case 0x9D:    return(SPEC | ALTD | 'f');    /* alt grey cursor right */
  199. case 0x9F:    return(SPEC | ALTD | 'g');    /* alt grey end */
  200. case 0xA0:    return(SPEC | ALTD | 'h');    /* alt grey cursor down */
  201. case 0xA1:    return(SPEC | ALTD | 'i');    /* alt grey page down */
  202. case 0xA2:    return(SPEC | ALTD | 'j');    /* alt grey insert */
  203. case 0xA3:    return(SPEC | ALTD | 'k');    /* alt grey delete */
  204.  
  205. case 0xA6:    return(SPEC | ALTD | 'l');    /* alt grey enter */
  206. case 0xA4:    return(SPEC | ALTD | '/');    /* alt grey / */
  207. case 0x37:    return(SPEC | ALTD | '*');    /* alt grey * */
  208. case 0x4A:    return(SPEC | ALTD | '-');    /* alt grey - */
  209. case 0x4E:    return(SPEC | ALTD | '+');    /* alt grey + */
  210.  
  211. case 0x95:    return(SPEC | CTRL | '/');    /* ctrl grey / */
  212. case 0x96:    return(SPEC | CTRL | '*');    /* ctrl grey * */
  213. case 0x8E:    return(SPEC | CTRL | '-');    /* ctrl grey - */
  214. case 0x90:    return(SPEC | CTRL | '+');    /* ctrl grey + */
  215.  
  216. #endif
  217.  
  218.     }
  219. /* printf("[ALT %d] ", c); */
  220.  
  221.     return(ALTD | c);
  222. }
  223.  
  224. #endif
  225. #endif
  226.