-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathkeycode.c
76 lines (69 loc) · 1.61 KB
/
keycode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "../keycode.h"
/*
* Structs to store key mappings not handled by XStringToKeysym() on some
* Linux systems.
*/
struct XSpecialCharacterMapping {
char name;
MMKeyCode code;
};
struct XSpecialCharacterMapping XSpecialCharacterTable[] = {
{'~', XK_asciitilde},
{'_', XK_underscore},
{'[', XK_bracketleft},
{']', XK_bracketright},
{'!', XK_exclam},
{'\'', XK_quotedbl},
{'#', XK_numbersign},
{'$', XK_dollar},
{'%', XK_percent},
{'&', XK_ampersand},
{'\'', XK_quoteright},
{'*', XK_asterisk},
{'+', XK_plus},
{',', XK_comma},
{'-', XK_minus},
{'.', XK_period},
{'?', XK_question},
{'<', XK_less},
{'>', XK_greater},
{'=', XK_equal},
{'@', XK_at},
{':', XK_colon},
{';', XK_semicolon},
{'\\', XK_backslash},
{'`', XK_grave},
{'{', XK_braceleft},
{'}', XK_braceright},
{'|', XK_bar},
{'^', XK_asciicircum},
{'(', XK_parenleft},
{')', XK_parenright},
{' ', XK_space},
{'/', XK_slash},
{'\t', XK_Tab},
{'\n', XK_Return}
};
MMKeyCode keyCodeForChar(const char c)
{
MMKeyCode code;
char buf[2];
buf[0] = c;
buf[1] = '\0';
code = XStringToKeysym(buf);
if (code == NoSymbol) {
/* Some special keys are apparently not handled properly by
* XStringToKeysym() on some systems, so search for them instead in our
* mapping table. */
size_t i;
const size_t specialCharacterCount =
sizeof(XSpecialCharacterTable) / sizeof(XSpecialCharacterTable[0]);
for (i = 0; i < specialCharacterCount; ++i) {
if (c == XSpecialCharacterTable[i].name) {
code = XSpecialCharacterTable[i].code;
break;
}
}
}
return code;
}