-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.c
190 lines (153 loc) · 3.97 KB
/
main.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <Windows.h>
HHOOK _hook;
KBDLLHOOKSTRUCT kbdStruct;
BOOLEAN isEmulation;
BOOLEAN ReplaceButton(DWORD newButton) {
if (isEmulation) {
isEmulation = FALSE;
return FALSE;
}
isEmulation = TRUE;
keybd_event(newButton, 0, 0, 0);
keybd_event(newButton, 0, KEYEVENTF_KEYUP, 0);
return TRUE;
}
LRESULT __stdcall HookCallback(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode >= 0 && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)) {
kbdStruct = *((KBDLLHOOKSTRUCT*)lParam);
switch (kbdStruct.vkCode) {
case VK_VOLUME_MUTE:
if (ReplaceButton(VK_F1)) return 1;
break;
case VK_F1:
if (ReplaceButton(VK_VOLUME_MUTE)) return 1;
break;
case VK_VOLUME_DOWN:
if (ReplaceButton(VK_F2)) return 1;
break;
case VK_F2:
if (ReplaceButton(VK_VOLUME_DOWN)) return 1;
break;
case VK_VOLUME_UP:
if (ReplaceButton(VK_F3)) return 1;
break;
case VK_F3:
if (ReplaceButton(VK_VOLUME_UP)) return 1;
break;
case VK_MEDIA_PREV_TRACK:
if (ReplaceButton(VK_F4)) return 1;
break;
case VK_F4:
if (ReplaceButton(VK_MEDIA_PREV_TRACK)) return 1;
break;
case VK_MEDIA_PLAY_PAUSE:
if (ReplaceButton(VK_F5)) return 1;
break;
case VK_F5:
if (ReplaceButton(VK_MEDIA_PLAY_PAUSE)) return 1;
break;
case VK_MEDIA_NEXT_TRACK:
if (ReplaceButton(VK_F6)) return 1;
break;
case VK_F6:
if (ReplaceButton(VK_MEDIA_NEXT_TRACK)) return 1;
break;
case VK_BROWSER_BACK:
if (ReplaceButton(VK_F7)) return 1;
break;
case VK_F7:
if (ReplaceButton(VK_BROWSER_BACK)) return 1;
break;
case VK_BROWSER_HOME:
if (ReplaceButton(VK_F8)) return 1;
break;
case VK_F8:
if (ReplaceButton(VK_BROWSER_HOME)) return 1;
break;
case VK_APPS:
if (ReplaceButton(VK_F9)) return 1;
break;
case VK_F9:
if (ReplaceButton(VK_APPS)) return 1;
break;
// F10
case VK_F21:
if (!isEmulation) {
isEmulation = TRUE;
if (GetKeyState(VK_LWIN) & 0x8000)
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
if (GetKeyState(VK_LSHIFT) & 0x8000)
keybd_event(VK_LSHIFT, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_F10, 0, 0, 0);
keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
return 1;
}
else {
isEmulation = FALSE;
}
break;
case VK_F10:
if (!isEmulation) {
isEmulation = TRUE;
keybd_event(VK_LSHIFT, 0, 0, 0);
keybd_event(VK_LWIN, 0, 0, 0);
keybd_event(VK_F21, 0, 0, 0);
keybd_event(VK_F21, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LSHIFT, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
return 1;
}
else {
isEmulation = FALSE;
}
break;
// F11
case 0x9:
if ((GetKeyState(VK_LCONTROL) & 0x8000) && (GetKeyState(VK_LMENU) & 0x8000)) {
if (!isEmulation) {
isEmulation = TRUE;
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LMENU, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_F11, 0, 0, 0);
keybd_event(VK_F11, 0, KEYEVENTF_KEYUP, 0);
return 1;
}
else {
isEmulation = FALSE;
}
}
break;
case VK_F11:
if (!isEmulation) {
isEmulation = TRUE;
keybd_event(VK_LCONTROL, 0, 0, 0);
keybd_event(VK_LMENU, 0, 0, 0);
keybd_event(0x9, 0, 0, 0);
keybd_event(0x9, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LMENU, 0, KEYEVENTF_KEYUP, 0);
return 1;
}
else {
isEmulation = FALSE;
}
break;
}
}
return CallNextHookEx(_hook, nCode, wParam, lParam);
}
void SetHook() {
if (!(_hook = SetWindowsHookEx(WH_KEYBOARD_LL, HookCallback, NULL, 0))) {
MessageBox(NULL, TEXT("Failed to install ThinkPad Compact Bluetooth Keyboard with TrackPoint hot key switch hook"), TEXT("Error"), MB_ICONERROR);
}
}
void ReleaseHook() {
UnhookWindowsHookEx(_hook);
}
void main() {
ShowWindow(GetConsoleWindow(), SW_HIDE);
SetHook();
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
}
}