Skip to content

Commit

Permalink
Fixing keycode issues with improper use of LLKHF_EXTENDED on Windows. F…
Browse files Browse the repository at this point in the history
…ixes #147 and #179
  • Loading branch information
kwhat committed Apr 26, 2024
1 parent a966797 commit 0ec1fd1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
24 changes: 12 additions & 12 deletions include/uiohook.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ typedef void (*dispatcher_t)(uiohook_event * const, void *);
// Begin Numeric Zone
#define VC_NUM_LOCK 0x0090
#define VC_KP_CLEAR 0x000C
#define VC_CLEAR VC_KP_CLEAR // Deprecated
#define VC_CLEAR VC_KP_CLEAR // Deprecated, the clear key is only available on the keypad.

#define VC_KP_DIVIDE 0x006F
#define VC_KP_MULTIPLY 0x006A
Expand All @@ -298,17 +298,17 @@ typedef void (*dispatcher_t)(uiohook_event * const, void *);
#define VC_KP_8 0x0068
#define VC_KP_9 0x0069

#define VC_KP_END 0xEE00 | VC_KP_1
#define VC_KP_DOWN 0xEE00 | VC_KP_2
#define VC_KP_PAGE_DOWN 0xEE00 | VC_KP_3
#define VC_KP_LEFT 0xEE00 | VC_KP_4
#define VC_KP_BEGIN 0xEE00 | VC_KP_5
#define VC_KP_RIGHT 0xEE00 | VC_KP_6
#define VC_KP_HOME 0xEE00 | VC_KP_7
#define VC_KP_UP 0xEE00 | VC_KP_8
#define VC_KP_PAGE_UP 0xEE00 | VC_KP_9
#define VC_KP_INSERT 0xEE00 | VC_KP_0
#define VC_KP_DELETE 0xEE00 | VC_KP_SEPARATOR
#define VC_KP_END 0xEE00 | VC_END
#define VC_KP_DOWN 0xEE00 | VC_DOWN
#define VC_KP_PAGE_DOWN 0xEE00 | VC_PAGE_DOWN
#define VC_KP_LEFT 0xEE00 | VC_LEFT
#define VC_KP_BEGIN 0xEE00 | VC_BEGIN
#define VC_KP_RIGHT 0xEE00 | VC_RIGHT
#define VC_KP_HOME 0xEE00 | VC_HOME
#define VC_KP_UP 0xEE00 | VC_UP
#define VC_KP_PAGE_UP 0xEE00 | VC_PAGE_UP
#define VC_KP_INSERT 0xEE00 | VC_INSERT
#define VC_KP_DELETE 0xEE00 | VC_DELETE
// End Numeric Zone


Expand Down
18 changes: 11 additions & 7 deletions src/windows/input_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,18 @@ unsigned short keycode_to_scancode(DWORD vk_code, DWORD flags) {
if (vk_code < sizeof(keycode_scancode_table) / sizeof(keycode_scancode_table[0])) {
scancode = keycode_scancode_table[vk_code][0];

// Check the extended key flag as defined at:
// https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#extended-key-flag
if (flags & LLKHF_EXTENDED) {
logger(LOG_LEVEL_DEBUG, "%s [%u]: Using normal lookup for vk_code: %li\n",
__FUNCTION__, __LINE__, vk_code);

switch (vk_code) {
case VK_RETURN:
scancode = VC_KP_ENTER;
break;
}
} else {
logger(LOG_LEVEL_DEBUG, "%s [%u]: Using extended lookup for vk_code: %li\n",
__FUNCTION__, __LINE__, vk_code);

Expand All @@ -319,14 +330,7 @@ unsigned short keycode_to_scancode(DWORD vk_code, DWORD flags) {
case VK_DELETE:
scancode |= 0xEE00;
break;

case VK_RETURN:
scancode |= 0x0E00;
break;
}
} else {
logger(LOG_LEVEL_DEBUG, "%s [%u]: Using normal lookup for vk_code: %li\n",
__FUNCTION__, __LINE__, vk_code);
}
}

Expand Down

0 comments on commit 0ec1fd1

Please sign in to comment.