Skip to content

Commit d983c7c

Browse files
committed
Fixed windows scan code conversion again.
Added pause key support.
1 parent a711f36 commit d983c7c

File tree

2 files changed

+9
-95
lines changed

2 files changed

+9
-95
lines changed

include/uiohook.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ typedef void (*dispatcher_t)(virtual_event *const);
219219

220220
#define VC_PRINTSCREEN 0x0E37
221221
#define VC_SCROLL_LOCK 0x0046
222-
//FIXME #define VC_PAUSE 0x0045
222+
#define VC_PAUSE 0x0045
223223

224224

225225
// Begin Edit Key Zone
@@ -268,8 +268,8 @@ typedef void (*dispatcher_t)(virtual_event *const);
268268
#define VC_SHIFT_R 0x0E36
269269
#define VC_CONTROL_L 0x001D
270270
#define VC_CONTROL_R 0x0E1D
271-
#define VC_ALT_L 0xD038 // Option or Alt Key
272-
#define VC_ALT_R 0xDE38 // Option or Alt Key
271+
#define VC_ALT_L 0x0038 // Option or Alt Key
272+
#define VC_ALT_R 0x0E38 // Option or Alt Key
273273
#define VC_META_L 0x0E5B // Windows or Command Key
274274
#define VC_META_R 0x0E5C // Windows or Command Key
275275
#define VC_CONTEXT_MENU 0x0E5D

windows/hook_callback.c

Lines changed: 6 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -152,63 +152,16 @@ LRESULT CALLBACK keyboard_event_proc(int nCode, WPARAM wParam, LPARAM lParam) {
152152
else if (kbhook->vkCode == VK_LWIN) set_modifier_mask(MASK_META_L);
153153
else if (kbhook->vkCode == VK_RWIN) set_modifier_mask(MASK_META_R);
154154

155-
156-
// Workaround for Windows numpad keys.
157-
/*
158-
if (kbhook->vkCode == VK_RETURN && (kbhook->flags & 0x01) != 0) {
159-
jkey = NativeToJKey(VK_NUMPAD_RETURN);
160-
}
161-
else if (kbhook->vkCode == VK_PRIOR && (kbhook->flags & 0x01) == 0) {
162-
jkey = NativeToJKey(VK_NUMPAD_PRIOR);
163-
}
164-
else if (kbhook->vkCode == VK_NEXT && (kbhook->flags & 0x01) == 0) {
165-
jkey = NativeToJKey(VK_NUMPAD_NEXT);
166-
}
167-
else if (kbhook->vkCode == VK_END && (kbhook->flags & 0x01) == 0) {
168-
jkey = NativeToJKey(VK_NUMPAD_END);
169-
}
170-
else if (kbhook->vkCode == VK_HOME && (kbhook->flags & 0x01) == 0) {
171-
jkey = NativeToJKey(VK_NUMPAD_HOME);
172-
}
173-
else if (kbhook->vkCode == VK_LEFT && (kbhook->flags & 0x01) == 0) {
174-
jkey = NativeToJKey(VK_NUMPAD_LEFT);
175-
}
176-
else if (kbhook->vkCode == VK_UP && (kbhook->flags & 0x01) == 0) {
177-
jkey = NativeToJKey(VK_NUMPAD_UP);
178-
}
179-
else if (kbhook->vkCode == VK_RIGHT && (kbhook->flags & 0x01) == 0) {
180-
jkey = NativeToJKey(VK_NUMPAD_RIGHT);
181-
}
182-
else if (kbhook->vkCode == VK_DOWN && (kbhook->flags & 0x01) == 0) {
183-
jkey = NativeToJKey(VK_NUMPAD_DOWN);
184-
}
185-
else if (kbhook->vkCode == VK_INSERT && (kbhook->flags & 0x01) == 0) {
186-
jkey = NativeToJKey(VK_NUMPAD_INSERT);
187-
}
188-
else if (kbhook->vkCode == VK_DELETE && (kbhook->flags & 0x01) == 0) {
189-
jkey = NativeToJKey(VK_NUMPAD_DELETE);
190-
}
191-
else {
192-
jkey = NativeToJKey(kbhook->vkCode);
193-
}
194-
*/
195-
196155
// Fire key pressed event.
197156
event.type = EVENT_KEY_PRESSED;
198157
event.mask = get_modifiers();
199158

200159
event.data.keyboard.keycode = kbhook->scanCode;
201-
if (kbhook->flags != 0x00) {
202-
event.data.keyboard.keycode |= ((UINT8) kbhook->flags ^ 0x0F) << 8;
160+
if (kbhook->flags & 0x03) {
161+
// This is a bit of a hack, but it seems to work and it is fast.
162+
event.data.keyboard.keycode |= (UINT8) ((kbhook->flags ^ 0x0F) & 0x0F) << 8;
203163
}
204164

205-
// FIXME Remove this log entry as it is only for testing.
206-
fprintf(stdout, "%s [%u]: kbhook->flags == %#X; kbhook->scanCode == %#X; kbhook->keyCode == %#X\n",
207-
__FUNCTION__, __LINE__,
208-
kbhook->flags,
209-
kbhook->scanCode,
210-
event.data.keyboard.keycode);
211-
212165
event.data.keyboard.rawcode = kbhook->vkCode;
213166
event.data.keyboard.keychar = CHAR_UNDEFINED;
214167

@@ -243,53 +196,14 @@ LRESULT CALLBACK keyboard_event_proc(int nCode, WPARAM wParam, LPARAM lParam) {
243196
else if (kbhook->vkCode == VK_LWIN) unset_modifier_mask(MASK_META_L);
244197
else if (kbhook->vkCode == VK_RWIN) unset_modifier_mask(MASK_META_R);
245198

246-
// Workaround for Windows numpad keys.
247-
/*
248-
if (kbhook->vkCode == VK_RETURN && (kbhook->flags & 0x01) != 0) {
249-
jkey = NativeToJKey(VK_NUMPAD_RETURN);
250-
}
251-
else if (kbhook->vkCode == VK_PRIOR && (kbhook->flags & 0x01) == 0) {
252-
jkey = NativeToJKey(VK_NUMPAD_PRIOR);
253-
}
254-
else if (kbhook->vkCode == VK_NEXT && (kbhook->flags & 0x01) == 0) {
255-
jkey = NativeToJKey(VK_NUMPAD_NEXT);
256-
}
257-
else if (kbhook->vkCode == VK_END && (kbhook->flags & 0x01) == 0) {
258-
jkey = NativeToJKey(VK_NUMPAD_END);
259-
}
260-
else if (kbhook->vkCode == VK_HOME && (kbhook->flags & 0x01) == 0) {
261-
jkey = NativeToJKey(VK_NUMPAD_HOME);
262-
}
263-
else if (kbhook->vkCode == VK_LEFT && (kbhook->flags & 0x01) == 0) {
264-
jkey = NativeToJKey(VK_NUMPAD_LEFT);
265-
}
266-
else if (kbhook->vkCode == VK_UP && (kbhook->flags & 0x01) == 0) {
267-
jkey = NativeToJKey(VK_NUMPAD_UP);
268-
}
269-
else if (kbhook->vkCode == VK_RIGHT && (kbhook->flags & 0x01) == 0) {
270-
jkey = NativeToJKey(VK_NUMPAD_RIGHT);
271-
}
272-
else if (kbhook->vkCode == VK_DOWN && (kbhook->flags & 0x01) == 0) {
273-
jkey = NativeToJKey(VK_NUMPAD_DOWN);
274-
}
275-
else if (kbhook->vkCode == VK_INSERT && (kbhook->flags & 0x01) == 0) {
276-
jkey = NativeToJKey(VK_NUMPAD_INSERT);
277-
}
278-
else if (kbhook->vkCode == VK_DELETE && (kbhook->flags & 0x01) == 0) {
279-
jkey = NativeToJKey(VK_NUMPAD_DELETE);
280-
}
281-
else {
282-
jkey = NativeToJKey(kbhook->vkCode);
283-
}
284-
*/
285-
286199
// Fire key released event.
287200
event.type = EVENT_KEY_RELEASED;
288201
event.mask = get_modifiers();
289202

290203
event.data.keyboard.keycode = kbhook->scanCode;
291-
if (kbhook->flags != 0x00) {
292-
event.data.keyboard.keycode |= ((UINT8) kbhook->flags ^ 0x0F) << 8;
204+
if (kbhook->flags & 0x03) {
205+
// This is a bit of a hack, but it seems to work and it is fast.
206+
event.data.keyboard.keycode |= (UINT8) ((kbhook->flags ^ 0x0F) & 0x0F) << 8;
293207
}
294208

295209
event.data.keyboard.rawcode = kbhook->vkCode;

0 commit comments

Comments
 (0)