forked from rime/squirrel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macos_keycode.m
91 lines (82 loc) · 1.69 KB
/
macos_keycode.m
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#import "macos_keycode.h"
#import <rime/key_table.h>
int osx_modifiers_to_rime_modifiers(unsigned modifiers)
{
int ret = 0;
if (modifiers & OSX_SHIFT_MASK)
ret |= kShiftMask;
if (modifiers & OSX_CTRL_MASK)
ret |= kControlMask;
if (modifiers & OSX_ALT_MASK)
ret |= kAltMask;
if (modifiers & OSX_COMMAND_MASK)
ret |= kSuperMask;
return ret;
}
int osx_keycode_to_rime_keycode(int keycode, int keychar, int shift)
{
int ret = 0;
switch (keycode) {
case OSX_VK_SPACE:
ret = XK_space;
break;
case OSX_VK_TAB:
ret = XK_Tab;
break;
case OSX_VK_ENTER:
ret = XK_Return;
break;
case OSX_VK_BACK_SPACE:
ret = XK_BackSpace;
break;
case OSX_VK_ESCAPE:
ret = XK_Escape;
break;
case OSX_VK_PAGE_UP:
ret = XK_Prior;
break;
case OSX_VK_PAGE_DOWN:
ret = XK_Next;
break;
case OSX_VK_END:
ret = XK_End;
break;
case OSX_VK_HOME:
ret = XK_Home;
break;
case OSX_VK_LEFT:
ret = XK_Left;
break;
case OSX_VK_UP:
ret = XK_Up;
break;
case OSX_VK_RIGHT:
ret = XK_Right;
break;
case OSX_VK_DOWN:
ret = XK_Down;
break;
case OSX_VK_DELETE:
ret = XK_Delete;
break;
case OSX_VK_CONTROL_L:
ret = XK_Control_L;
break;
case OSX_VK_CONTROL_R:
ret = XK_Control_R;
break;
case OSX_VK_SHIFT_L:
ret = XK_Shift_L;
break;
case OSX_VK_SHIFT_R:
ret = XK_Shift_R;
break;
case OSX_VK_ALT:
ret = XK_Alt_L;
break;
default:
ret = (keychar >= 0x20 && keychar <= 0x7e) ? keychar : 0;
break;
}
return ret;
}