Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
KeyMap.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: KeyMap.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Weapon class
13 */
14 
15 #include "MemDebug.h"
16 #include "Keyboard.h"
17 #include "KeyMap.h"
18 #include "Game.h"
19 #include "Ship.h"
20 
21 // +----------------------------------------------------------------------+
22 
23 struct KeyName
24 {
25  int category;
26  int key;
27  const char* name;
28  const char* desc;
29 };
30 
31 static KeyName key_action_table[] = {
32  { KeyMap::KEY_FLIGHT, KEY_PLUS_X, "KEY_PLUS_X", "Translate Right" },
33  { KeyMap::KEY_FLIGHT, KEY_MINUS_X, "KEY_MINUS_X", "Translate Left" },
34  { KeyMap::KEY_FLIGHT, KEY_PLUS_Y, "KEY_PLUS_Y", "Translate Forward" },
35  { KeyMap::KEY_FLIGHT, KEY_MINUS_Y, "KEY_MINUS_Y", "Translate Aft" },
36  { KeyMap::KEY_FLIGHT, KEY_PLUS_Z, "KEY_PLUS_Z", "Translate Up" },
37  { KeyMap::KEY_FLIGHT, KEY_MINUS_Z, "KEY_MINUS_Z", "Translate Down" },
38 
39  { KeyMap::KEY_FLIGHT, KEY_PITCH_UP, "KEY_PITCH_UP", "Pitch Up" },
40  { KeyMap::KEY_FLIGHT, KEY_PITCH_DOWN, "KEY_PITCH_DOWN", "Pitch Down" },
41  { KeyMap::KEY_FLIGHT, KEY_YAW_LEFT, "KEY_YAW_LEFT", "Yaw Left" },
42  { KeyMap::KEY_FLIGHT, KEY_YAW_RIGHT, "KEY_YAW_RIGHT", "Yaw Right" },
43  { KeyMap::KEY_FLIGHT, KEY_ROLL_LEFT, "KEY_ROLL_LEFT", "Roll Left" },
44  { KeyMap::KEY_FLIGHT, KEY_ROLL_RIGHT, "KEY_ROLL_RIGHT", "Roll Right" },
45  { KeyMap::KEY_FLIGHT, KEY_CENTER, "KEY_CENTER", "Center" },
46  { KeyMap::KEY_FLIGHT, KEY_ROLL_ENABLE, "KEY_ROLL_ENABLE", "Roll Enable" },
47  { KeyMap::KEY_FLIGHT, KEY_SWAP_ROLL_YAW, "KEY_SWAP_ROLL_YAW", "Swap Ctrl Axes" },
48 
49  { KeyMap::KEY_WEAPONS, KEY_ACTION_0, "KEY_ACTION_0", "Fire Primary" },
50  { KeyMap::KEY_WEAPONS, KEY_ACTION_1, "KEY_ACTION_1", "Fire Secondary" },
51  { KeyMap::KEY_WEAPONS, KEY_ACTION_2, "KEY_ACTION_2", "Action 2" },
52  { KeyMap::KEY_WEAPONS, KEY_ACTION_3, "KEY_ACTION_3", "Action 3" },
53 
54  { KeyMap::KEY_FLIGHT, KEY_CONTROL_MODEL, "KEY_CONTROL_MODEL" },
55 
56  { KeyMap::KEY_FLIGHT, KEY_MOUSE_SELECT, "KEY_MOUSE_SELECT" },
57  { KeyMap::KEY_FLIGHT, KEY_MOUSE_SENSE, "KEY_MOUSE_SENSE" },
58  { KeyMap::KEY_FLIGHT, KEY_MOUSE_SWAP, "KEY_MOUSE_SWAP" },
59  { KeyMap::KEY_FLIGHT, KEY_MOUSE_INVERT, "KEY_MOUSE_INVERT" },
60  { KeyMap::KEY_FLIGHT, KEY_MOUSE_ACTIVE, "KEY_MOUSE_ACTIVE", "Toggle Mouse Ctrl" },
61 
62  { KeyMap::KEY_FLIGHT, KEY_JOY_SELECT, "KEY_JOY_SELECT" },
63  { KeyMap::KEY_FLIGHT, KEY_JOY_RUDDER, "KEY_JOY_RUDDER" },
64  { KeyMap::KEY_FLIGHT, KEY_JOY_THROTTLE, "KEY_JOY_THROTTLE" },
65  { KeyMap::KEY_FLIGHT, KEY_JOY_SENSE, "KEY_JOY_SENSE" },
66  { KeyMap::KEY_FLIGHT, KEY_JOY_DEAD_ZONE, "KEY_JOY_DEAD_ZONE" },
67  { KeyMap::KEY_FLIGHT, KEY_JOY_SWAP, "KEY_JOY_SWAP" },
68 
69  { KeyMap::KEY_FLIGHT, KEY_AXIS_YAW, "KEY_AXIS_YAW" },
70  { KeyMap::KEY_FLIGHT, KEY_AXIS_PITCH, "KEY_AXIS_PITCH" },
71  { KeyMap::KEY_FLIGHT, KEY_AXIS_ROLL, "KEY_AXIS_ROLL" },
72  { KeyMap::KEY_FLIGHT, KEY_AXIS_THROTTLE, "KEY_AXIS_THROTTLE" },
73  { KeyMap::KEY_FLIGHT, KEY_AXIS_YAW_INVERT, "KEY_AXIS_YAW_INVERT" },
74  { KeyMap::KEY_FLIGHT, KEY_AXIS_PITCH_INVERT, "KEY_AXIS_PITCH_INVERT" },
75  { KeyMap::KEY_FLIGHT, KEY_AXIS_ROLL_INVERT, "KEY_AXIS_ROLL_INVERT" },
76  { KeyMap::KEY_FLIGHT, KEY_AXIS_THROTTLE_INVERT, "KEY_AXIS_THROTTLE_INVERT" },
77 
78  { KeyMap::KEY_MISC, KEY_EXIT, "KEY_EXIT", "Exit" },
79  { KeyMap::KEY_MISC, KEY_PAUSE, "KEY_PAUSE", "Pause" },
80  // { KeyMap::KEY_VIEW, KEY_NEXT_VIEW, "KEY_NEXT_VIEW", "Next View" },
81  { KeyMap::KEY_VIEW, KEY_TARGET_PADLOCK, "KEY_TARGET_PADLOCK","Padlock Target" },
82  { KeyMap::KEY_VIEW, KEY_THREAT_PADLOCK, "KEY_THREAT_PADLOCK","Padlock Threat" },
83  { KeyMap::KEY_WEAPONS, KEY_LOCK_TARGET, "KEY_LOCK_TARGET", "Lock Target" },
84  { KeyMap::KEY_WEAPONS, KEY_LOCK_THREAT, "KEY_LOCK_THREAT", "Lock Threat" },
85  { KeyMap::KEY_WEAPONS, KEY_LOCK_CLOSEST_SHIP, "KEY_LOCK_CLOSEST_SHIP", "Lock Closest Ship" },
86  { KeyMap::KEY_WEAPONS, KEY_LOCK_CLOSEST_THREAT, "KEY_LOCK_CLOSEST_THREAT", "Lock Closest Threat" },
87  { KeyMap::KEY_WEAPONS, KEY_LOCK_HOSTILE_SHIP, "KEY_LOCK_HOSTILE_SHIP", "Lock Hostile Ship" },
88  { KeyMap::KEY_WEAPONS, KEY_LOCK_HOSTILE_THREAT, "KEY_LOCK_HOSTILE_THREAT", "Lock Hostile Threat" },
89  { KeyMap::KEY_WEAPONS, KEY_CYCLE_SUBTARGET, "KEY_CYCLE_SUBTARGET", "Target Subsystem" },
90  { KeyMap::KEY_WEAPONS, KEY_PREV_SUBTARGET, "KEY_PREV_SUBTARGET", "Previous Subsystem" },
91  { KeyMap::KEY_FLIGHT, KEY_AUTO_NAV, "KEY_AUTO_NAV", "Autonav" },
92  { KeyMap::KEY_MISC, KEY_TIME_COMPRESS, "KEY_TIME_COMPRESS", "Compress Time" },
93  { KeyMap::KEY_MISC, KEY_TIME_EXPAND, "KEY_TIME_EXPAND", "Expand Time" },
94  { KeyMap::KEY_MISC, KEY_TIME_SKIP, "KEY_TIME_SKIP", "Skip to Next Event" },
95 
96  { KeyMap::KEY_FLIGHT, KEY_THROTTLE_UP, "KEY_THROTTLE_UP", "Throttle Up" },
97  { KeyMap::KEY_FLIGHT, KEY_THROTTLE_DOWN, "KEY_THROTTLE_DOWN", "Throttle Down" },
98  { KeyMap::KEY_FLIGHT, KEY_THROTTLE_ZERO, "KEY_THROTTLE_ZERO", "All Stop" },
99  { KeyMap::KEY_FLIGHT, KEY_THROTTLE_FULL, "KEY_THROTTLE_FULL", "Full Throttle" },
100  { KeyMap::KEY_FLIGHT, KEY_AUGMENTER, "KEY_AUGMENTER", "Augmenter" },
101  { KeyMap::KEY_FLIGHT, KEY_FLCS_MODE_AUTO, "KEY_FLCS_MODE_AUTO","FLCS Mode Toggle" },
102  { KeyMap::KEY_FLIGHT, KEY_COMMAND_MODE, "KEY_COMMAND_MODE", "CMD Mode Toggle" },
103  { KeyMap::KEY_FLIGHT, KEY_DROP_ORBIT, "KEY_DROP_ORBIT", "Break Orbit" },
104  { KeyMap::KEY_FLIGHT, KEY_GEAR_TOGGLE, "KEY_GEAR_TOGGLE", "Landing Gear" },
105  { KeyMap::KEY_FLIGHT, KEY_NAVLIGHT_TOGGLE, "KEY_NAVLIGHT_TOGGLE","Nav Lights" },
106 
107  { KeyMap::KEY_WEAPONS, KEY_CYCLE_PRIMARY, "KEY_CYCLE_PRIMARY", "Cycle Primary" },
108  { KeyMap::KEY_WEAPONS, KEY_CYCLE_SECONDARY, "KEY_CYCLE_SECONDARY", "Cycle Secondary" },
109 
110  { KeyMap::KEY_VIEW, KEY_HUD_INST, "KEY_HUD_INST", "Instr. Display" },
111  { KeyMap::KEY_VIEW, KEY_CAM_BRIDGE, "KEY_CAM_BRIDGE", "Bridge Cam" },
112  { KeyMap::KEY_VIEW, KEY_CAM_VIRT, "KEY_CAM_VIRT", "Virtual Cockpit" },
113  { KeyMap::KEY_VIEW, KEY_CAM_CHASE, "KEY_CAM_CHASE", "Chase Cam" },
114  { KeyMap::KEY_VIEW, KEY_CAM_DROP, "KEY_CAM_DROP", "Drop Cam" },
115  { KeyMap::KEY_VIEW, KEY_CAM_EXTERN, "KEY_CAM_EXTERN", "Orbit Cam" },
116  { KeyMap::KEY_MISC, KEY_HUD_MODE, "KEY_HUD_MODE", "HUD Mode" },
117  { KeyMap::KEY_MISC, KEY_HUD_COLOR, "KEY_HUD_COLOR", "HUD Color" },
118  { KeyMap::KEY_MISC, KEY_HUD_WARN, "KEY_HUD_WARN", "Master Caution" },
119  { KeyMap::KEY_MISC, KEY_NAV_DLG, "KEY_NAV_DLG", "NAV Window" },
120  { KeyMap::KEY_MISC, KEY_WEP_DLG, "KEY_WEP_DLG", "TAC Overlay" },
121  { KeyMap::KEY_MISC, KEY_FLT_DLG, "KEY_FLT_DLG", "FLT Window" },
122  { KeyMap::KEY_MISC, KEY_ENG_DLG, "KEY_ENG_DLG", "ENG Window" },
123 
124  { KeyMap::KEY_VIEW, KEY_ZOOM_WIDE, "KEY_ZOOM_WIDE", "Toggle Wide Angle" },
125  { KeyMap::KEY_VIEW, KEY_ZOOM_IN, "KEY_ZOOM_IN", "Zoom In" },
126  { KeyMap::KEY_VIEW, KEY_ZOOM_OUT, "KEY_ZOOM_OUT", "Zoom Out" },
127 
128  { KeyMap::KEY_VIEW, KEY_CAM_VIRT_PLUS_AZ, "KEY_CAM_VIRT_PLUS_AZ", "Look Left" },
129  { KeyMap::KEY_VIEW, KEY_CAM_VIRT_MINUS_AZ, "KEY_CAM_VIRT_MINUS_AZ", "Look Right" },
130  { KeyMap::KEY_VIEW, KEY_CAM_VIRT_PLUS_EL, "KEY_CAM_VIRT_PLUS_EL", "Look Up" },
131  { KeyMap::KEY_VIEW, KEY_CAM_VIRT_MINUS_EL, "KEY_CAM_VIRT_MINUS_EL", "Look Down" },
132  { KeyMap::KEY_VIEW, KEY_CAM_CYCLE_OBJECT, "KEY_CAM_CYCLE_OBJECT", "View Next Object" },
133  { KeyMap::KEY_VIEW, KEY_CAM_EXT_PLUS_AZ, "KEY_CAM_EXT_PLUS_AZ", "View Spin Left" },
134  { KeyMap::KEY_VIEW, KEY_CAM_EXT_MINUS_AZ, "KEY_CAM_EXT_MINUS_AZ", "View Spin Right" },
135  { KeyMap::KEY_VIEW, KEY_CAM_EXT_PLUS_EL, "KEY_CAM_EXT_PLUS_EL", "View Raise" },
136  { KeyMap::KEY_VIEW, KEY_CAM_EXT_MINUS_EL, "KEY_CAM_EXT_MINUS_EL", "View Lower" },
137  { KeyMap::KEY_VIEW, KEY_CAM_EXT_PLUS_RANGE, "KEY_CAM_EXT_PLUS_RANGE", "View Farther" },
138  { KeyMap::KEY_VIEW, KEY_CAM_EXT_MINUS_RANGE,"KEY_CAM_EXT_MINUS_RANGE", "View Closer" },
139  { KeyMap::KEY_VIEW, KEY_CAM_VIEW_SELECTION, "KEY_CAM_VIEW_SELECTION", "View Selection" },
140 
141  { KeyMap::KEY_WEAPONS, KEY_TARGET_SELECTION, "KEY_TARGET_SELECTION", "Target Selection" },
142  { KeyMap::KEY_MISC, KEY_RADIO_MENU, "KEY_RADIO_MENU", "Radio Call" },
143  { KeyMap::KEY_MISC, KEY_QUANTUM_MENU, "KEY_QUANTUM_MENU", "Quantum Drive" },
144 
145  { KeyMap::KEY_MISC, KEY_MFD1, "KEY_MFD1", "MFD 1" },
146  { KeyMap::KEY_MISC, KEY_MFD2, "KEY_MFD2", "MFD 2" },
147  { KeyMap::KEY_MISC, KEY_MFD3, "KEY_MFD3", "MFD 3" },
148  { KeyMap::KEY_MISC, KEY_MFD4, "KEY_MFD4", "MFD 4" },
149  { KeyMap::KEY_MISC, KEY_SELF_DESTRUCT, "KEY_SELF_DESTRUCT", "Self Destruct" },
150 
151  { KeyMap::KEY_MISC, KEY_COMM_ATTACK_TGT, "KEY_COMM_ATTACK_TGT", "'Attack Tgt'" },
152  { KeyMap::KEY_MISC, KEY_COMM_ESCORT_TGT, "KEY_COMM_ESCORT_TGT", "'Escort Tgt'" },
153  { KeyMap::KEY_MISC, KEY_COMM_WEP_FREE, "KEY_COMM_WEP_FREE", "'Break & Attack'" },
154  { KeyMap::KEY_MISC, KEY_COMM_WEP_HOLD, "KEY_COMM_WEP_HOLD", "'Form Up'" },
155  { KeyMap::KEY_MISC, KEY_COMM_COVER_ME, "KEY_COMM_COVER_ME", "'Help Me Out!'" },
156  { KeyMap::KEY_MISC, KEY_COMM_SKIP_NAV, "KEY_COMM_SKIP_NAV", "'Skip Navpoint'" },
157  { KeyMap::KEY_MISC, KEY_COMM_RETURN_TO_BASE,"KEY_COMM_RETURN_TO_BASE", "'Return to Base'" },
158  { KeyMap::KEY_MISC, KEY_COMM_CALL_INBOUND, "KEY_COMM_CALL_INBOUND", "'Call Inbound'" },
159  { KeyMap::KEY_MISC, KEY_COMM_REQUEST_PICTURE, "KEY_COMM_REQUEST_PICTURE", "'Request Picture'" },
160  { KeyMap::KEY_MISC, KEY_COMM_REQUEST_SUPPORT, "KEY_COMM_REQUEST_SUPPORT", "'Request Support'" },
161  { KeyMap::KEY_MISC, KEY_CHAT_BROADCAST, "KEY_CHAT_BROADCAST", "Chat Broadcast" },
162  { KeyMap::KEY_MISC, KEY_CHAT_TEAM, "KEY_CHAT_TEAM", "Chat Team" },
163  { KeyMap::KEY_MISC, KEY_CHAT_WING, "KEY_CHAT_WING", "Chat Wingman" },
164  { KeyMap::KEY_MISC, KEY_CHAT_UNIT, "KEY_CHAT_UNIT", "Chat Unit" },
165 
166  { KeyMap::KEY_WEAPONS, KEY_SHIELDS_UP, "KEY_SHIELDS_UP", "Raise Shields" },
167  { KeyMap::KEY_WEAPONS, KEY_SHIELDS_DOWN, "KEY_SHIELDS_DOWN", "Lower Shields" },
168  { KeyMap::KEY_WEAPONS, KEY_SHIELDS_FULL, "KEY_SHIELDS_FULL", "Full Shields" },
169  { KeyMap::KEY_WEAPONS, KEY_SHIELDS_ZERO, "KEY_SHIELDS_ZERO", "Zero Shields" },
170 
171  { KeyMap::KEY_WEAPONS, KEY_SENSOR_MODE, "KEY_SENSOR_MODE", "Sensor Mode" },
172  { KeyMap::KEY_WEAPONS, KEY_SENSOR_GROUND_MODE, "KEY_SENSOR_GROUND_MODE", "Sensor AGM" },
173  { KeyMap::KEY_WEAPONS, KEY_SENSOR_BEAM, "KEY_SENSOR_BEAM", "Sensor Sweep Angle" },
174  { KeyMap::KEY_WEAPONS, KEY_SENSOR_RANGE_PLUS, "KEY_SENSOR_RANGE_PLUS", "Inc Sensor Range" },
175  { KeyMap::KEY_WEAPONS, KEY_SENSOR_RANGE_MINUS, "KEY_SENSOR_RANGE_MINUS", "Dec Sensor Range" },
176  { KeyMap::KEY_WEAPONS, KEY_EMCON_PLUS, "KEY_EMCON_PLUS", "Inc EMCON Level" },
177  { KeyMap::KEY_WEAPONS, KEY_EMCON_MINUS, "KEY_EMCON_MINUS", "Dec EMCON Level" },
178 
179  { KeyMap::KEY_WEAPONS, KEY_DECOY, "KEY_DECOY", "Launch Decoy" },
180  { KeyMap::KEY_WEAPONS, KEY_LAUNCH_PROBE, "KEY_LAUNCH_PROBE", "Launch Probe" },
181 
182 };
183 
184 static KeyName key_key_table[] = {
185  { 0, VK_ESCAPE, "VK_ESCAPE", "Escape" },
186  { 0, VK_UP, "VK_UP", "Up" },
187  { 0, VK_DOWN, "VK_DOWN", "Down" },
188  { 0, VK_LEFT, "VK_LEFT", "Left" },
189  { 0, VK_RIGHT, "VK_RIGHT", "Right" },
190  { 0, VK_NEXT, "VK_NEXT", "Pg Down" },
191  { 0, VK_PRIOR, "VK_PRIOR", "Pg Up" },
192  { 0, VK_ADD, "VK_ADD", "+" },
193  { 0, VK_SUBTRACT, "VK_SUBTRACT", "-" },
194  { 0, VK_MULTIPLY, "VK_MULTIPLY", "*" },
195  { 0, VK_DIVIDE, "VK_DIVIDE", "/" },
196  { 0, VK_SPACE, "VK_SPACE", "Space" },
197  { 0, VK_TAB, "VK_TAB", "Tab" },
198  { 0, VK_RETURN, "VK_RETURN", "Enter" },
199  { 0, VK_HOME, "VK_HOME", "Home" },
200  { 0, VK_END, "VK_END", "End" },
201  { 0, VK_SHIFT, "VK_SHIFT", "Shift" },
202  { 0, VK_CONTROL, "VK_CONTROL", "Ctrl" },
203  { 0, VK_MENU, "VK_MENU", "Alt" },
204 
205  { 0, VK_DECIMAL, "VK_DECIMAL", "." },
206  { 0, VK_SEPARATOR, "VK_SEPARATOR", "Separator" },
207  { 0, VK_PAUSE, "VK_PAUSE", "Pause" },
208  { 0, VK_BACK, "VK_BACK", "Backspace" },
209  { 0, VK_INSERT, "VK_INSERT", "Insert" },
210  { 0, VK_DELETE, "VK_DELETE", "Delete" },
211  { 0, 20, "CAP", "CapsLock" },
212  { 0, 144, "NUM", "NumLock" },
213  { 0, 145, "SCROLL", "Scroll" },
214  { 0, 44, "PRINT", "PrintScr" },
215 
216  { 0, VK_NUMPAD0, "VK_NUMPAD0", "Num 0" },
217  { 0, VK_NUMPAD1, "VK_NUMPAD1", "Num 1" },
218  { 0, VK_NUMPAD2, "VK_NUMPAD2", "Num 2" },
219  { 0, VK_NUMPAD3, "VK_NUMPAD3", "Num 3" },
220  { 0, VK_NUMPAD4, "VK_NUMPAD4", "Num 4" },
221  { 0, VK_NUMPAD5, "VK_NUMPAD5", "Num 5" },
222  { 0, VK_NUMPAD6, "VK_NUMPAD6", "Num 6" },
223  { 0, VK_NUMPAD7, "VK_NUMPAD7", "Num 7" },
224  { 0, VK_NUMPAD8, "VK_NUMPAD8", "Num 8" },
225  { 0, VK_NUMPAD9, "VK_NUMPAD9", "Num 9" },
226 
227  { 0, VK_F1, "VK_F1", "F1" },
228  { 0, VK_F2, "VK_F2", "F2" },
229  { 0, VK_F3, "VK_F3", "F3" },
230  { 0, VK_F4, "VK_F4", "F4" },
231  { 0, VK_F5, "VK_F5", "F5" },
232  { 0, VK_F6, "VK_F6", "F6" },
233  { 0, VK_F7, "VK_F7", "F7" },
234  { 0, VK_F8, "VK_F8", "F8" },
235  { 0, VK_F9, "VK_F9", "F9" },
236  { 0, VK_F10, "VK_F10", "F10" },
237  { 0, VK_F11, "VK_F11", "F11" },
238  { 0, VK_F12, "VK_F12", "F12" },
239 
240  { 0, KEY_JOY_1, "KEY_JOY_1", "Joy 1" },
241  { 0, KEY_JOY_2, "KEY_JOY_2", "Joy 2" },
242  { 0, KEY_JOY_3, "KEY_JOY_3", "Joy 3" },
243  { 0, KEY_JOY_4, "KEY_JOY_4", "Joy 4" },
244  { 0, KEY_JOY_5, "KEY_JOY_5", "Joy 5" },
245  { 0, KEY_JOY_6, "KEY_JOY_6", "Joy 6" },
246  { 0, KEY_JOY_7, "KEY_JOY_7", "Joy 7" },
247  { 0, KEY_JOY_8, "KEY_JOY_8", "Joy 8" },
248  { 0, KEY_JOY_9, "KEY_JOY_9", "Joy 9" },
249  { 0, KEY_JOY_10, "KEY_JOY_10", "Joy 10" },
250  { 0, KEY_JOY_11, "KEY_JOY_11", "Joy 11" },
251  { 0, KEY_JOY_12, "KEY_JOY_12", "Joy 12" },
252  { 0, KEY_JOY_13, "KEY_JOY_13", "Joy 13" },
253  { 0, KEY_JOY_14, "KEY_JOY_14", "Joy 14" },
254  { 0, KEY_JOY_15, "KEY_JOY_15", "Joy 15" },
255  { 0, KEY_JOY_16, "KEY_JOY_16", "Joy 16" },
256 
257  { 0, KEY_POV_0_UP, "KEY_POV_0_UP", "Hat 1 Up" },
258  { 0, KEY_POV_0_DOWN, "KEY_POV_0_DOWN", "Hat 1 Down" },
259  { 0, KEY_POV_0_LEFT, "KEY_POV_0_LEFT", "Hat 1 Left" },
260  { 0, KEY_POV_0_RIGHT, "KEY_POV_0_RIGHT", "Hat 1 Right" },
261  { 0, KEY_POV_1_UP, "KEY_POV_1_UP", "Hat 2 Up" },
262  { 0, KEY_POV_1_DOWN, "KEY_POV_1_DOWN", "Hat 2 Down" },
263  { 0, KEY_POV_1_LEFT, "KEY_POV_1_LEFT", "Hat 2 Left" },
264  { 0, KEY_POV_1_RIGHT, "KEY_POV_1_RIGHT", "Hat 2 Right" },
265  { 0, KEY_POV_2_UP, "KEY_POV_2_UP", "Hat 3 Up" },
266  { 0, KEY_POV_2_DOWN, "KEY_POV_2_DOWN", "Hat 3 Down" },
267  { 0, KEY_POV_2_LEFT, "KEY_POV_2_LEFT", "Hat 3 Left" },
268  { 0, KEY_POV_2_RIGHT, "KEY_POV_2_RIGHT", "Hat 3 Right" },
269  { 0, KEY_POV_3_UP, "KEY_POV_3_UP", "Hat 4 Up" },
270  { 0, KEY_POV_3_DOWN, "KEY_POV_3_DOWN", "Hat 4 Down" },
271  { 0, KEY_POV_3_LEFT, "KEY_POV_3_LEFT", "Hat 4 Left" },
272  { 0, KEY_POV_3_RIGHT, "KEY_POV_3_RIGHT", "Hat 4 Right" },
273 
274  { 0, 186, ";", ";" },
275  { 0, 188, ",", "<" },
276  { 0, 190, ".", ">" },
277  { 0, 191, "/", "/" },
278  { 0, 192, "~", "~" },
279  { 0, 219, "[", "[" },
280  { 0, 220, "\\", "\\" },
281  { 0, 221, "]", "]" },
282  { 0, 222, "'", "'" },
283 
284  { 0, '0', "0", "0" },
285  { 0, '1', "1", "1" },
286  { 0, '2', "2", "2" },
287  { 0, '3', "3", "3" },
288  { 0, '4', "4", "4" },
289  { 0, '5', "5", "5" },
290  { 0, '6', "6", "6" },
291  { 0, '7', "7", "7" },
292  { 0, '8', "8", "8" },
293  { 0, '9', "9", "9" },
294 
295  { 0, 'A', "A", "A" },
296  { 0, 'B', "B", "B" },
297  { 0, 'C', "C", "C" },
298  { 0, 'D', "D", "D" },
299  { 0, 'E', "E", "E" },
300  { 0, 'F', "F", "F" },
301  { 0, 'G', "G", "G" },
302  { 0, 'H', "H", "H" },
303  { 0, 'I', "I", "I" },
304  { 0, 'J', "J", "J" },
305  { 0, 'K', "K", "K" },
306  { 0, 'L', "L", "L" },
307  { 0, 'M', "M", "M" },
308  { 0, 'N', "N", "N" },
309  { 0, 'O', "O", "O" },
310  { 0, 'P', "P", "P" },
311  { 0, 'Q', "Q", "Q" },
312  { 0, 'R', "R", "R" },
313  { 0, 'S', "S", "S" },
314  { 0, 'T', "T", "T" },
315  { 0, 'U', "U", "U" },
316  { 0, 'V', "V", "V" },
317  { 0, 'W', "W", "W" },
318  { 0, 'X', "X", "X" },
319  { 0, 'Y', "Y", "Y" },
320  { 0, 'Z', "Z", "Z" },
321 
322 };
323 
324 // +----------------------------------------------------------------------+
325 
326 int KeyMap::GetKeyAction(const char* act_str)
327 {
328  if (!act_str) return -1;
329 
330  int nactions = sizeof(key_action_table) / sizeof(KeyName);
331 
332  for (int i = 0; i < nactions; i++)
333  if (!_stricmp(act_str, key_action_table[i].name))
334  return key_action_table[i].key;
335 
336  return -1;
337 }
338 
339 // +----------------------------------------------------------------------+
340 
342 {
343  int nactions = sizeof(key_action_table) / sizeof(KeyName);
344 
345  for (int i = 0; i < nactions; i++)
346  if (key_action_table[i].key == act)
347  return i;
348 
349  return -1;
350 }
351 
352 // +----------------------------------------------------------------------+
353 
354 int KeyMap::GetKeyKey(const char* key_str)
355 {
356  if (!key_str) return 0;
357 
358  if (*key_str == '=') {
359  int value = 0;
360  sscanf_s(key_str, "=%d", &value);
361  return value;
362  }
363 
364  int nkeys = sizeof(key_key_table) / sizeof(KeyName);
365 
366  for (int i = 0; i < nkeys; i++)
367  if (!_stricmp(key_str, key_key_table[i].name))
368  return key_key_table[i].key;
369 
370  return 0;
371 }
372 
373 // +----------------------------------------------------------------------+
374 
376 {
377  int nkeys = sizeof(key_key_table) / sizeof(KeyName);
378 
379  for (int i = 0; i < nkeys; i++)
380  if (key_key_table[i].key == key)
381  return i;
382 
383  return -1;
384 }
385 
386 // +----------------------------------------------------------------------+
387 
388 
390 : nkeys(0)
391 {
392  int n = BuildDefaultKeyMap();
393  DefaultKeyMap(n);
394 }
395 
397 { }
398 
399 // +----------------------------------------------------------------------+
400 
401 int
403 {
404  int i = 0;
405 
406  defmap[i++] = KeyMapEntry(KEY_PITCH_UP, VK_DOWN);
407  defmap[i++] = KeyMapEntry(KEY_PITCH_DOWN, VK_UP);
408  defmap[i++] = KeyMapEntry(KEY_YAW_LEFT, VK_LEFT);
409  defmap[i++] = KeyMapEntry(KEY_YAW_RIGHT, VK_RIGHT);
410  defmap[i++] = KeyMapEntry(KEY_ROLL_LEFT, VK_NUMPAD7);
411  defmap[i++] = KeyMapEntry(KEY_ROLL_RIGHT, VK_NUMPAD9);
412 
413  defmap[i++] = KeyMapEntry(KEY_PLUS_X, 190, 0, KEY_POV_0_RIGHT); // .
414  defmap[i++] = KeyMapEntry(KEY_MINUS_X, 188, 0, KEY_POV_0_LEFT); // ,
415  defmap[i++] = KeyMapEntry(KEY_PLUS_Y, VK_HOME);
416  defmap[i++] = KeyMapEntry(KEY_MINUS_Y, VK_END);
417  defmap[i++] = KeyMapEntry(KEY_PLUS_Z, VK_PRIOR, 0, KEY_POV_0_UP);
418  defmap[i++] = KeyMapEntry(KEY_MINUS_Z, VK_NEXT, 0, KEY_POV_0_DOWN);
419 
420  defmap[i++] = KeyMapEntry(KEY_ACTION_0, VK_CONTROL, 0, KEY_JOY_1);
421  defmap[i++] = KeyMapEntry(KEY_ACTION_1, VK_SPACE, 0, KEY_JOY_2);
422 
423 
424  defmap[i++] = KeyMapEntry(KEY_THROTTLE_UP, 'A');
425  defmap[i++] = KeyMapEntry(KEY_THROTTLE_DOWN, 'Z');
426  defmap[i++] = KeyMapEntry(KEY_THROTTLE_FULL, 'A', VK_SHIFT);
427  defmap[i++] = KeyMapEntry(KEY_THROTTLE_ZERO, 'Z', VK_SHIFT);
428  defmap[i++] = KeyMapEntry(KEY_AUGMENTER, VK_TAB);
430  defmap[i++] = KeyMapEntry(KEY_COMMAND_MODE, 'M', VK_SHIFT);
431 
432  defmap[i++] = KeyMapEntry(KEY_CYCLE_PRIMARY, VK_BACK, VK_SHIFT);
433  defmap[i++] = KeyMapEntry(KEY_CYCLE_SECONDARY, VK_BACK);
434  defmap[i++] = KeyMapEntry(KEY_LOCK_TARGET, 'T', 0, KEY_JOY_3);
435  defmap[i++] = KeyMapEntry(KEY_LOCK_THREAT, 'T', VK_SHIFT);
437  defmap[i++] = KeyMapEntry(KEY_LOCK_CLOSEST_THREAT, 'U', VK_SHIFT);
439  defmap[i++] = KeyMapEntry(KEY_LOCK_HOSTILE_THREAT, 'Y', VK_SHIFT);
441  defmap[i++] = KeyMapEntry(KEY_PREV_SUBTARGET, 186, VK_SHIFT);
442 
443  defmap[i++] = KeyMapEntry(KEY_DECOY, 'D', 0, KEY_JOY_4);
444  defmap[i++] = KeyMapEntry(KEY_GEAR_TOGGLE, 'G');
446 
447  defmap[i++] = KeyMapEntry(KEY_AUTO_NAV, 'N', VK_SHIFT);
448  defmap[i++] = KeyMapEntry(KEY_DROP_ORBIT, 'O');
449 
450  defmap[i++] = KeyMapEntry(KEY_SHIELDS_UP, 'S');
451  defmap[i++] = KeyMapEntry(KEY_SHIELDS_DOWN, 'X');
452  defmap[i++] = KeyMapEntry(KEY_SHIELDS_FULL, 'S', VK_SHIFT);
453  defmap[i++] = KeyMapEntry(KEY_SHIELDS_ZERO, 'X', VK_SHIFT);
454 
455  defmap[i++] = KeyMapEntry(KEY_SENSOR_MODE, VK_F5);
456  defmap[i++] = KeyMapEntry(KEY_SENSOR_GROUND_MODE, VK_F5, VK_SHIFT);
457  defmap[i++] = KeyMapEntry(KEY_LAUNCH_PROBE, VK_F6);
460  defmap[i++] = KeyMapEntry(KEY_EMCON_MINUS, VK_F9);
461  defmap[i++] = KeyMapEntry(KEY_EMCON_PLUS, VK_F10);
462 
463  defmap[i++] = KeyMapEntry(KEY_EXIT, VK_ESCAPE);
464  defmap[i++] = KeyMapEntry(KEY_PAUSE, VK_PAUSE);
465  // defmap[i++] = KeyMapEntry(KEY_NEXT_VIEW, VK_TAB);
466  defmap[i++] = KeyMapEntry(KEY_TIME_EXPAND, VK_DELETE);
467  defmap[i++] = KeyMapEntry(KEY_TIME_COMPRESS, VK_INSERT);
468  defmap[i++] = KeyMapEntry(KEY_TIME_SKIP, VK_INSERT, VK_SHIFT);
469 
470  defmap[i++] = KeyMapEntry(KEY_CAM_BRIDGE, VK_F1);
471  defmap[i++] = KeyMapEntry(KEY_CAM_VIRT, VK_F1, VK_SHIFT);
472  defmap[i++] = KeyMapEntry(KEY_CAM_CHASE, VK_F2);
473  defmap[i++] = KeyMapEntry(KEY_CAM_DROP, VK_F2, VK_SHIFT);
474  defmap[i++] = KeyMapEntry(KEY_CAM_EXTERN, VK_F3);
475  defmap[i++] = KeyMapEntry(KEY_TARGET_PADLOCK, VK_F4);
476 
477  defmap[i++] = KeyMapEntry(KEY_ZOOM_WIDE, 'K');
478  defmap[i++] = KeyMapEntry(KEY_HUD_MODE, 'H');
479  defmap[i++] = KeyMapEntry(KEY_HUD_COLOR, 'H', VK_SHIFT);
480  defmap[i++] = KeyMapEntry(KEY_HUD_WARN, 'C');
481  defmap[i++] = KeyMapEntry(KEY_HUD_INST, 'I');
482  defmap[i++] = KeyMapEntry(KEY_NAV_DLG, 'N');
483  defmap[i++] = KeyMapEntry(KEY_WEP_DLG, 'W');
484  defmap[i++] = KeyMapEntry(KEY_ENG_DLG, 'E');
485  defmap[i++] = KeyMapEntry(KEY_FLT_DLG, 'F');
486  defmap[i++] = KeyMapEntry(KEY_RADIO_MENU, 'R');
487  defmap[i++] = KeyMapEntry(KEY_QUANTUM_MENU, 'Q');
488 
489  defmap[i++] = KeyMapEntry(KEY_MFD1, 219); // [
490  defmap[i++] = KeyMapEntry(KEY_MFD2, 221); // ]
491  defmap[i++] = KeyMapEntry(KEY_SELF_DESTRUCT, VK_ESCAPE, VK_SHIFT);
492 
493  defmap[i++] = KeyMapEntry(KEY_CAM_CYCLE_OBJECT, VK_TAB, VK_SHIFT);
494  defmap[i++] = KeyMapEntry(KEY_CAM_EXT_PLUS_AZ, VK_LEFT, VK_SHIFT);
495  defmap[i++] = KeyMapEntry(KEY_CAM_EXT_MINUS_AZ, VK_RIGHT, VK_SHIFT);
496  defmap[i++] = KeyMapEntry(KEY_CAM_EXT_PLUS_EL, VK_UP, VK_SHIFT);
497  defmap[i++] = KeyMapEntry(KEY_CAM_EXT_MINUS_EL, VK_DOWN, VK_SHIFT);
498  defmap[i++] = KeyMapEntry(KEY_CAM_EXT_PLUS_RANGE, VK_SUBTRACT);
501  defmap[i++] = KeyMapEntry(KEY_CAM_VIRT_PLUS_AZ, VK_LEFT, VK_SHIFT);
502  defmap[i++] = KeyMapEntry(KEY_CAM_VIRT_MINUS_AZ, VK_RIGHT, VK_SHIFT);
503  defmap[i++] = KeyMapEntry(KEY_CAM_VIRT_PLUS_EL, VK_DOWN, VK_SHIFT);
504  defmap[i++] = KeyMapEntry(KEY_CAM_VIRT_MINUS_EL, VK_UP, VK_SHIFT);
505 
506  defmap[i++] = KeyMapEntry(KEY_SWAP_ROLL_YAW, 'J');
507 
508  defmap[i++] = KeyMapEntry(KEY_COMM_ATTACK_TGT, 'A', VK_MENU);
509  defmap[i++] = KeyMapEntry(KEY_COMM_ESCORT_TGT, 'E', VK_MENU);
510  defmap[i++] = KeyMapEntry(KEY_COMM_WEP_FREE, 'B', VK_MENU);
511  defmap[i++] = KeyMapEntry(KEY_COMM_WEP_HOLD, 'F', VK_MENU);
512  defmap[i++] = KeyMapEntry(KEY_COMM_COVER_ME, 'H', VK_MENU);
513  defmap[i++] = KeyMapEntry(KEY_COMM_SKIP_NAV, 'N', VK_MENU);
514  defmap[i++] = KeyMapEntry(KEY_COMM_RETURN_TO_BASE, 'R', VK_MENU);
515  defmap[i++] = KeyMapEntry(KEY_COMM_CALL_INBOUND, 'I', VK_MENU);
516  defmap[i++] = KeyMapEntry(KEY_COMM_REQUEST_PICTURE,'P', VK_MENU);
517  defmap[i++] = KeyMapEntry(KEY_COMM_REQUEST_SUPPORT,'S', VK_MENU);
518 
519  defmap[i++] = KeyMapEntry(KEY_CHAT_BROADCAST, '1', VK_MENU);
520  defmap[i++] = KeyMapEntry(KEY_CHAT_TEAM, '2', VK_MENU);
521  defmap[i++] = KeyMapEntry(KEY_CHAT_WING, '3', VK_MENU);
522  defmap[i++] = KeyMapEntry(KEY_CHAT_UNIT, '4', VK_MENU);
523 
525 
526  defmap[i++] = KeyMapEntry(KEY_JOY_SELECT, 1);
527  defmap[i++] = KeyMapEntry(KEY_JOY_RUDDER, 0);
529  defmap[i++] = KeyMapEntry(KEY_JOY_SENSE, 1);
530  defmap[i++] = KeyMapEntry(KEY_JOY_DEAD_ZONE, 500);
531 
533  defmap[i++] = KeyMapEntry(KEY_MOUSE_SENSE, 10);
534  defmap[i++] = KeyMapEntry(KEY_MOUSE_ACTIVE, 192); // ~ key
535 
536  /*** For Debug Convenience Only: ***/
537  defmap[i++] = KeyMapEntry(KEY_INC_STARDATE, VK_F11);
538  defmap[i++] = KeyMapEntry(KEY_DEC_STARDATE, VK_F11, VK_SHIFT);
539  /***/
540 
541  return i;
542 }
543 
544 // +----------------------------------------------------------------------+
545 
546 int
548 {
549  for (int i = 0; i < max_keys; i++)
550  map[i] = defmap[i];
551 
552  nkeys = max_keys;
553  return nkeys;
554 }
555 
556 void
557 KeyMap::Bind(int a, int k, int s)
558 {
559  if (!a) return;
560 
561  for (int i = 0; i < nkeys; i++) {
562  if (map[i].act == a) {
563  map[i].key = k;
564  map[i].alt = s;
565 
566  return;
567  }
568  }
569 
570  map[nkeys++] = KeyMapEntry(a, k, s);
571 }
572 
573 // +----------------------------------------------------------------------+
574 
575 int
576 KeyMap::LoadKeyMap(const char* filename, int max_keys)
577 {
578  FILE* f;
579  fopen_s(&f, filename, "r");
580 
581  if (!f) return nkeys;
582 
583  char line[256];
584 
585  while (fgets(line, sizeof(line), f)) {
586  int act = -1, key = -1, alt = 0, joy = -1;
587  char act_str[128], key_str[128], alt_str[128], joy_str[128];
588 
589  ZeroMemory(act_str, sizeof(act_str));
590  ZeroMemory(key_str, sizeof(key_str));
591  ZeroMemory(alt_str, sizeof(alt_str));
592  ZeroMemory(joy_str, sizeof(joy_str));
593 
594  sscanf(line, "%s %s %s %s", act_str, key_str, alt_str, joy_str);
595 
596  act = GetKeyAction(act_str);
597  key = GetKeyKey(key_str);
598  alt = GetKeyKey(alt_str);
599  joy = GetKeyKey(joy_str);
600 
601  if (act != -1 && key != -1) {
602  if (act == KEY_CONTROL_MODEL)
604 
605  int mapped = false;
606 
607  for (int i = 0; i < max_keys && !mapped; i++) {
608  if (map[i].act == act) {
609  Print(" Remapping: '%s' => %s(%d) %s(%d) %s(%d)\n",
610  act_str, key_str, key, alt_str, alt, joy_str, joy);
611 
612  map[i] = KeyMapEntry(act, key, alt, joy);
613  mapped = true;
614  }
615  }
616 
617  if (!mapped) {
618  Print(" Mapping: '%s' => %s(%d) %s(%d) %s(%d)\n",
619  act_str, key_str, key, alt_str, alt, joy_str, joy);
620  map[nkeys++] = KeyMapEntry(act, key, alt, joy);
621  }
622  }
623 
624  if (nkeys >= max_keys-1) {
625  Print(" Too many keys in configuration...\n");
626  break;
627  }
628  }
629 
630  fclose(f);
631  return nkeys;
632 }
633 
634 // +----------------------------------------------------------------------+
635 
636 int
637 KeyMap::SaveKeyMap(const char* filename, int max_keys)
638 {
639  FILE* f;
640  fopen_s(&f, filename, "w");
641  if (!f) return 0;
642 
643  for (int i = 0; i < nkeys; i++) {
644  if (map[i].act >= KEY_CONTROL_MODEL &&
645  map[i].act <= KEY_AXIS_THROTTLE_INVERT) {
646 
647  int a = GetKeyActionIndex(map[i].act);
648 
649  fprintf(f, "%-24s =%d\n", key_action_table[a].name, map[i].key);
650  }
651 
652  else if (map[i] != defmap[i]) {
653  int a = GetKeyActionIndex(map[i].act);
654  int k = GetKeyKeyIndex(map[i].key);
655  int s = GetKeyKeyIndex(map[i].alt);
656  int j = GetKeyKeyIndex(map[i].joy);
657 
658  if (a > -1) {
659  if (j > -1) {
660  if (s > -1) {
661  fprintf(f, "%-24s %-16s %-16s %-16s\n",
662  key_action_table[a].name,
663  key_key_table[ k].name,
664  key_key_table[ s].name,
665  key_key_table[ j].name);
666  }
667  else if (k > -1) {
668  fprintf(f, "%-24s %-16s %-16s %-16s\n",
669  key_action_table[a].name,
670  key_key_table[ k].name,
671  "null",
672  key_key_table[ j].name);
673  }
674  else {
675  fprintf(f, "%-24s %-16s %-16s %-16s\n",
676  key_action_table[a].name,
677  "null",
678  "null",
679  key_key_table[ j].name);
680  }
681  }
682  else if (s > -1) {
683  fprintf(f, "%-24s %-16s %-16s\n",
684  key_action_table[a].name,
685  key_key_table[ k].name,
686  key_key_table[ s].name);
687  }
688  else if (k > -1) {
689  fprintf(f, "%-24s %-16s\n",
690  key_action_table[a].name,
691  key_key_table[ k].name);
692  }
693  }
694  }
695  }
696 
697  fclose(f);
698  return nkeys;
699 }
700 
701 // +----------------------------------------------------------------------+
702 
703 int
705 {
706  int nactions = sizeof(key_action_table) / sizeof(KeyName);
707 
708  for (int i = 0; i < nactions; i++) {
709  if (map[n].act == key_action_table[i].key) {
710  return key_action_table[i].category;
711  }
712  }
713 
714  return KEY_MISC;
715 }
716 
717 // +----------------------------------------------------------------------+
718 
719 int
721 {
722  for (int n = 0; n < nkeys; n++)
723  if (map[n].act == act)
724  return n;
725  return -1;
726 }
727 
728 // +----------------------------------------------------------------------+
729 
730 const char*
732 {
733  int nactions = sizeof(key_action_table) / sizeof(KeyName);
734 
735  for (int i = 0; i < nactions; i++) {
736  if (map[n].act == key_action_table[i].key) {
737  if (key_action_table[i].desc)
738  return key_action_table[i].desc;
739 
740  return key_action_table[i].name;
741  }
742  }
743 
744  return 0;
745 }
746 
747 // +----------------------------------------------------------------------+
748 
749 static char key_desc[32];
750 
751 const char*
753 {
754  if (n >= 0 && n < 256)
755  return DescribeKey(map[n].key, map[n].alt, map[n].joy);
756 
757  return 0;
758 }
759 
760 const char*
761 KeyMap::DescribeKey(int vk, int shift, int j)
762 {
763  const char* key = 0;
764  const char* alt = 0;
765  const char* joy = 0;
766 
767  int nkeys = sizeof(key_key_table) / sizeof(KeyName);
768 
769  for (int i = 0; i < nkeys; i++) {
770  if (vk > 0 && vk == key_key_table[i].key) {
771  if (key_key_table[i].desc)
772  key = key_key_table[i].desc;
773  else
774  key = key_key_table[i].name;
775  }
776 
777  if (shift > 0 && shift == key_key_table[i].key) {
778  if (key_key_table[i].desc)
779  alt = key_key_table[i].desc;
780  else
781  alt = key_key_table[i].name;
782  }
783 
784  if (j > 0 && j == key_key_table[i].key) {
785  if (key_key_table[i].desc)
786  joy = key_key_table[i].desc;
787  else
788  joy = key_key_table[i].name;
789  }
790  }
791 
792  if (key) {
793  if (alt) {
794  sprintf_s(key_desc, "%s+%s", alt, key);
795  }
796  else {
797  strcpy_s(key_desc, key);
798  }
799 
800  if (joy) {
801  strcat_s(key_desc, ", ");
802  strcat_s(key_desc, joy);
803  }
804  }
805 
806  else if (joy) {
807  strcpy_s(key_desc, joy);
808  }
809 
810  else {
811  sprintf_s(key_desc, "%d", vk);
812  }
813 
814  return key_desc;
815 }
816 
817 int
819 {
820  int nkeys = sizeof(key_key_table) / sizeof(KeyName);
821 
822  if (n >= 0 && n < nkeys) {
823  return key_key_table[n].key;
824  }
825 
826  return 0;
827 }