nosound: fix implicit declaration of memset
[rofl0r-gnuboy.git] / keytable.c
blob48fc75f1ece603a5ff26a9e72339a49a7f02c4c7
1 /*
2 * keytable.c
4 * Key names to keycodes mapping.
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include <strings.h>
12 #include "input.h"
14 /* keytable - Mapping of key names to codes, and back. A single code
15 can have more than one name, in which case the first will be used
16 when saving config, but any may be used in setting config. */
18 keytable_t keytable[] =
20 { "shift", K_SHIFT },
21 { "ctrl", K_CTRL },
22 { "alt", K_ALT },
23 { "up", K_UP },
24 { "down", K_DOWN },
25 { "right", K_RIGHT },
26 { "left", K_LEFT },
27 { "enter", K_ENTER },
28 { "tab", K_TAB },
29 { "space", K_SPACE },
30 { "bs", K_BS },
31 { "backspace", K_BS }, /* dup */
32 { "del", K_DEL },
33 { "delete", K_DEL }, /* dup */
34 { "ins", K_INS },
35 { "insert", K_INS }, /* dup */
36 { "home", K_HOME },
37 { "end", K_END },
38 { "prior", K_PRIOR },
39 { "next", K_NEXT },
40 { "pgup", K_PRIOR }, /* duplicate for pgup/pgdn fans */
41 { "pgdn", K_NEXT }, /* ditto */
42 { "esc", K_ESC },
43 { "escape", K_ESC }, /* dup */
44 { "pause", K_PAUSE },
45 { "caps", K_CAPS },
46 { "capslock", K_CAPS }, /* dup */
47 { "numlock", K_NUMLOCK },
48 { "scroll", K_SCROLL },
50 { "minus", K_MINUS },
51 { "_", K_MINUS }, /* dup */
52 { "equals", K_EQUALS },
53 { "plus", K_EQUALS }, /* dup */
54 { "+", K_EQUALS }, /* dup */
55 { "tilde", K_TILDE },
56 { "backquote", K_TILDE }, /* dup */
57 { "`", K_TILDE }, /* dup */
58 { "slash", K_SLASH },
59 { "question", K_SLASH }, /* dup */
60 { "?", K_SLASH }, /* dup */
61 { "bslash", K_BSLASH },
62 { "backslash", K_BSLASH }, /* dup */
63 { "pipe", K_BSLASH }, /* dup */
64 { "|", K_BSLASH }, /* dup */
65 { "semi", K_SEMI },
66 { "semicolon", K_SEMI }, /* dup */
67 { "quote", K_QUOTE },
69 { "f1", K_F1 },
70 { "f2", K_F2 },
71 { "f3", K_F3 },
72 { "f4", K_F4 },
73 { "f5", K_F5 },
74 { "f6", K_F6 },
75 { "f7", K_F7 },
76 { "f8", K_F8 },
77 { "f9", K_F9 },
78 { "f10", K_F10 },
79 { "f11", K_F11 },
80 { "f12", K_F12 },
82 { "num0", K_NUM0 },
83 { "num1", K_NUM1 },
84 { "num2", K_NUM2 },
85 { "num3", K_NUM3 },
86 { "num4", K_NUM4 },
87 { "num5", K_NUM5 },
88 { "num6", K_NUM6 },
89 { "num7", K_NUM7 },
90 { "num8", K_NUM8 },
91 { "num9", K_NUM9 },
92 { "numplus", K_NUMPLUS },
93 { "numminus", K_NUMMINUS },
94 { "nummul", K_NUMMUL },
95 { "numdiv", K_NUMDIV },
96 { "numdot", K_NUMDOT },
97 { "numenter", K_NUMENTER },
99 /* Note that these are not presently used... */
100 { "mouse0", K_MOUSE0 },
101 { "mouse1", K_MOUSE1 },
102 { "mouse2", K_MOUSE2 },
103 { "mouse3", K_MOUSE3 },
104 { "mouse4", K_MOUSE4 },
106 { "joyleft", K_JOYLEFT },
107 { "joyright", K_JOYRIGHT },
108 { "joyup", K_JOYUP },
109 { "joydown", K_JOYDOWN },
111 { "joy0", K_JOY0 },
112 { "joy1", K_JOY1 },
113 { "joy2", K_JOY2 },
114 { "joy3", K_JOY3 },
115 { "joy4", K_JOY4 },
116 { "joy5", K_JOY5 },
117 { "joy6", K_JOY6 },
118 { "joy7", K_JOY7 },
119 { "joy8", K_JOY8 },
120 { "joy9", K_JOY9 },
121 { "joy10", K_JOY10 },
122 { "joy11", K_JOY11 },
123 { "joy12", K_JOY12 },
124 { "joy13", K_JOY13 },
125 { "joy14", K_JOY14 },
126 { "joy15", K_JOY15 },
128 { "xocheck", K_NUM1 },
129 { "xodown", K_NUM2 },
130 { "xocross", K_NUM3 },
131 { "xoleft", K_NUM4 },
132 { "xoright", K_NUM6 },
133 { "xobox", K_NUM7 },
134 { "xoup", K_NUM8 },
135 { "xocircle", K_NUM9 },
137 { NULL, 0 }
140 int k_keycode(char *name)
142 keytable_t *key;
144 for (key = keytable; key->name; key++)
145 if (!strcasecmp(key->name, name))
146 return key->code;
147 if (strlen(name) == 1)
148 return tolower(name[0]);
149 return 0;
152 char *k_keyname(int code)
154 keytable_t *key;
156 for (key = keytable; key->name; key++)
157 if (key->code == code)
158 return key->name;
159 return NULL;