You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
6.6 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* Keyboard handler routines header.
  2. Copyright by Salvador E. Tropea (SET) (1998,1999,2001)
  3. Covered by the GPL license. */
  4. #ifndef GKEY_HEADER_INCLUDED
  5. #define GKEY_HEADER_INCLUDED
  6. // A type for the BIOS ASCII/Scan
  7. typedef union
  8. {
  9. unsigned short full;
  10. struct
  11. {
  12. #ifdef TV_BIG_ENDIAN
  13. unsigned char scan;
  14. unsigned char ascii;
  15. #else
  16. unsigned char ascii;
  17. unsigned char scan;
  18. #endif
  19. } b;
  20. } KeyType;
  21. // Shift constants
  22. const ushort
  23. kbShiftCode=0x080,
  24. kbCtrlCode =0x100,
  25. kbAltRCode =0x400,
  26. kbAltLCode =0x200,
  27. kbKeyMask =0x07F;
  28. #ifdef Uses_FullSingleKeySymbols
  29. // Key constants, basically they are from the US keyboard, but all of them
  30. // are standard ASCII and not extended.
  31. const ushort
  32. kbUnkNown=0,
  33. kbA= 1,kbB= 2,kbC= 3,kbD= 4,kbE= 5,kbF= 6,kbG= 7,kbH= 8,kbI= 9,kbJ=10,kbK=11,
  34. kbL=12,kbM=13,kbN=14,kbO=15,kbP=16,kbQ=17,kbR=18,kbS=19,kbT=20,kbU=21,kbV=22,
  35. kbW=23,kbX=24,kbY=25,kbZ=26,
  36. kbOpenBrace=27,kbBackSlash=28,kbCloseBrace=29,kbPause=30,kbEsc=31,
  37. kb0=32,kb1=33,kb2=34,kb3=35,kb4=36,kb5=37,kb6=38,kb7=39,kb8=40,kb9=41,
  38. kbBackSpace=42,kbTab=43,kbEnter=44,kbColon=45,kbQuote=46,kbGrave=47,
  39. kbComma=48,kbStop=49,kbSlash=50,kbAsterisk=51,kbSpace=52,kbMinus=53,
  40. kbPlus=54,kbPrnScr=55,kbEqual=56,kbF1=57,kbF2=58,kbF3=59,kbF4=60,kbF5=61,
  41. kbF6=62,kbF7=63,kbF8=64,kbF9=65,kbF10=66,kbF11=67,kbF12=68,kbHome=69,
  42. kbUp=70,kbPgUp=71,kbLeft=72,kbRight=73,kbEnd=74,kbDown=75,kbPgDn=76,
  43. kbInsert=77,kbDelete=78,kbCaret=79,kbAdmid=80,kbDobleQuote=81,
  44. kbNumeral=82,kbDolar=83,kbPercent=84,kbAmper=85,kbOpenPar=86,
  45. kbClosePar=87,kbDoubleDot=88,kbLessThan=89,kbGreaterThan=90,
  46. kbQuestion=91,kbA_Roba=92,kbOr=93,kbUnderLine=94,kbOpenCurly=95,
  47. kbCloseCurly=96,kbTilde=97,kbMacro=98,kbWinLeft=99,kbWinRight=100,
  48. kbWinSel=101,
  49. kbMouse=102,kbEterm=103
  50. ;
  51. #endif
  52. /* IBM BIOS flags, not all implemented in most platforms */
  53. /*
  54. bit 15: SysReq key pressed;
  55. bit 14: Caps lock key currently down;
  56. bit 13: Num lock key currently down;
  57. bit 12: Scroll lock key currently down;
  58. bit 11: Right alt key is down;
  59. bit 10: Right ctrl key is down;
  60. bit 9: Left alt key is down;
  61. bit 8: Left ctrl key is down;
  62. bit 7: Insert toggle;
  63. bit 6: Caps lock toggle;
  64. bit 5: Num lock toggle;
  65. bit 4: Scroll lock toggle;
  66. bit 3: Either alt key is down (some machines, left only);
  67. bit 2: Either ctrl key is down;
  68. bit 1: Left shift key is down;
  69. bit 0: Right shift key is down
  70. */
  71. const unsigned
  72. kbSysReqPress =0x8000,
  73. kbCapsLockDown =0x4000,
  74. kbNumLockDown =0x2000,
  75. kbScrollLockDown =0x1000,
  76. kbRightAltDown =0x0800,
  77. kbRightCtrlDown =0x0400,
  78. kbLeftAltDown =0x0200,
  79. kbLeftCtrlDown =0x0100,
  80. kbInsertToggle =0x0080,
  81. kbCapsLockToggle =0x0040,
  82. kbNumLockToggle =0x0020,
  83. kbScrollLockToggle=0x0010,
  84. kbAltDown =0x0008,
  85. kbCtrlDown =0x0004,
  86. kbLeftShiftDown =0x0002,
  87. kbRightShiftDown =0x0001;
  88. struct TEvent;
  89. // A class to encapsulate the globals, all is static!
  90. class TGKey
  91. {
  92. public:
  93. TGKey() { resume(); };
  94. static void suspend();
  95. static void resume();
  96. static void (*Suspend)();
  97. static void (*Resume)();
  98. static int (*kbhit)();
  99. static void (*clear)();
  100. static ushort (*gkey)();
  101. // This is optional. Some platforms doesn't support it and the returned value
  102. // can be outdated.
  103. static unsigned (*getShiftState)();
  104. static void (*fillTEvent)(TEvent &e);
  105. // This is used by objects that needs Unicode16 as input
  106. static void (*fillCharCode)(TEvent &e);
  107. // Very used by: menues and hotkeys (buttons, status bar, etc).
  108. // Get the ascii associated to Alt+key, example Alt+A => A
  109. static char GetAltChar(unsigned short keyCode, uchar ascii);
  110. // The reverse (know the alt code when we know the ASCII)
  111. static ushort GetAltCode(uchar ch);
  112. // Find the code for the name of a key
  113. static ushort KeyNameToNumber(char *s);
  114. static const
  115. char *NumberToKeyName(unsigned val);
  116. // Alt keys interpretation
  117. static ushort GetAltSettings(void) { return AltSet; }
  118. static void SetAltSettings(ushort altSet) { AltSet=altSet; }
  119. // Special functions when we must deal with international stuff like a
  120. // shortcut in greek or cyrilic.
  121. // When a key character is over 128 and we want to know the ascii of
  122. // the key that generates it.
  123. static uchar (*NonASCII2ASCII)(uchar val);
  124. // Compares two values according to the associated ASCII.
  125. static int (*CompareASCII)(uchar val, uchar code);
  126. // Finds the Alt that generated it.
  127. static int (*AltInternat2ASCII)(TEvent &event);
  128. // Routine to setup the input code page
  129. static int (*SetCodePage)(int id);
  130. enum keyMode
  131. {
  132. // Linux styles
  133. linuxDisableKeyPatch=1,
  134. linuxEnableKeyPatch=2,
  135. // DOS
  136. // Should be incorporated to the remapping but I need volunteers
  137. //dosUS=0,
  138. //dosGreek737=20, No longer used
  139. dosUseBIOS=21,
  140. dosUseDirect=22,
  141. dosTranslateKeypad=23,
  142. dosNormalKeypad=24,
  143. // UNIX styles
  144. unixXterm=40,
  145. unixNoXterm=41,
  146. unixEterm=42
  147. };
  148. static void (*SetKbdMapping)(int version);
  149. static int (*GetKbdMapping)(int version);
  150. enum { codepage=0, unicode16=1 };
  151. static int getInputMode() { return inputMode; }
  152. protected:
  153. static uchar defaultNonASCII2ASCII(uchar val);
  154. static int defaultCompareASCII(uchar val, uchar code);
  155. static void defaultSetKbdMapping(int version);
  156. static int defaultGetKbdMapping(int version);
  157. static int defaultKbhit(void);
  158. static void defaultClear(void);
  159. static ushort defaultGkey(void);
  160. static unsigned defaultGetShiftState();
  161. static void defaultFillTEvent(TEvent &e);
  162. static void defaultSuspend();
  163. static void defaultResume();
  164. static int defaultSetCodePage(int id);
  165. static int defaultAltInternat2ASCII(TEvent &event);
  166. static void defaultFillCharCode(TEvent &e);
  167. // Greek table
  168. static stIntCodePairs GreekKeyboard[];
  169. // Russian table
  170. static stIntCodePairs RussianKeyboard[];
  171. // Generic tables
  172. static uchar KeyMap[128];
  173. static const uchar
  174. kbByASCII[128];
  175. static void FillKeyMapForCP(int id, stIntCodePairs *keyboard, size_t szKb);
  176. static uchar Generic_NonASCII2ASCII(uchar ascii);
  177. static int Generic_CompareASCII(uchar val, uchar code);
  178. static int Generic_AltInternat2ASCII(TEvent &e);
  179. // Needed for configuration.
  180. static char *KeyNames[];
  181. // 0 => Left alt is used
  182. // 1 => Right alt is used
  183. // 2 => Both alts are the same
  184. static ushort AltSet;
  185. static char suspended;
  186. //static KeyType rawCode;
  187. // SetKbdMapping:
  188. static int Mode;
  189. static int inputMode;
  190. };
  191. extern unsigned short getshiftstate();
  192. extern unsigned short __tv_getshiftstate();
  193. extern unsigned short __tv_GetRaw();
  194. extern int __tv_kbhit();
  195. extern void __tv_clear();
  196. #endif // GKEY_HEADER_INCLUDED