1 // --------------------------------------------------------------------------
2 // --
3 // -- KEY -- Keyboard handler.
4 // --
5 // --
6 // --------------------------------------------------------------------------
7
8 // --------------------------------------------------------------------------
9 // -- Includes
10 // --------------------------------------------------------------------------
11
12 // --------------------------------------------------------------------------
13 // -- Definitions
14 // --------------------------------------------------------------------------
15
16 // -- Basic types
17
18 typedef int KeyCommand;
19
20
21 // -- Absolutes
22 #define KEY_MAX_TRANSLATION 128
23 #define KEY_NO_COMMAND 0 // NOTHING can translate to this
24 // it indicates NO command
25
26
27 // -- Errors
28 enum KeyError {
29 KEY_NO_ERROR = 0,
30 KEY_OUT_OF_RANGE,
31 KEY_TOO_MANY
32
33 };
34
35 // -- keyStockKeys
36 enum KeyStockKeys {
37
38 KEY_ESC = 27,
39 KEY_A = 97,
40 KEY_Z = 122,
41 KEY_SHIFT_A = 65,
42 KEY_SHIFT_Z = 90,
43 KEY_ENTER = 13
44
45 };
46
47 // -- keyStockKeysExt
48 enum KeyStockKeysExt {
49
50 KEY_F1 = 59,
51 KEY_F2 = 60,
52 KEY_F3 = 61,
53 KEY_F4 = 62,
54 KEY_F5 = 63,
55 KEY_F6 = 64,
56 KEY_F7 = 65,
57 KEY_F8 = 66,
58 KEY_F9 = 67,
59 KEY_F10 = 68,
60 KEY_HOME = 71,
61 KEY_UP = 0,
62 KEY_PGUP = 73,
63 KEY_LEFT = 0,
64 KEY_RIGHT = 0,
65 KEY_END = 79,
66 KEY_DOWN = 0,
67 KEY_PGDOWN = 81,
68 KEY_INS = 82,
69 KEY_DEL = 83
70
71 };
72
73
74
75 // --------------------------------------------------------------------------
76 // -- Classes
77 // --------------------------------------------------------------------------
78
79 // -- key element. To make tables to register easier
80 struct KeyElement {
81
82 KeyCommand theCommand;
83 unsigned int keyCode;
84
85 };
86
87
88 // -- Basic key handler
89 class KeyHandler {
90
91 KeyCommand baseTranslation[KEY_MAX_TRANSLATION];
92 KeyCommand extTranslation[KEY_MAX_TRANSLATION];
93
94 public:
95
96 KeyHandler(void);
97
98
99 KeyError registerCommand(KeyCommand theCommand,
100 unsigned int keyCode,
101 Boolean extended );
102 KeyError registerCommand(KeyElement element,
103 Boolean extended );
104
105 KeyError registerTable(KeyElement *theTable,
106 int number,
107 Boolean extended );
108
109 KeyError unregisterCommand(unsigned int keyCode,
110 Boolean extended );
111 void invalidateAll(void);
112
113 void flush();
114 Boolean poll(unsigned char &theChar,
115 KeyCommand &theCommand); // non-blocking
116 KeyCommand get( unsigned char &theChar); // blocking
117
118
119 };
|