Skip to content

Commit

Permalink
Fix extended keys when simulating key events on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
TolikPylypchuk authored and kwhat committed Apr 13, 2024
1 parent f259ff3 commit b1e737d
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions src/windows/post_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@

#define MAX_WINDOWS_COORD_VALUE (1 << 16)

// TODO I doubt this table is complete.
// http://letcoderock.blogspot.fr/2011/10/sendinput-with-shift-key-not-work.html
static const uint16_t extend_key_table[10] = {
VK_UP,
VK_DOWN,
VK_LEFT,
VK_RIGHT,
VK_HOME,
VK_END,
VK_PRIOR, // PgUp
VK_NEXT, // PgDn
VK_INSERT,
VK_DELETE
};


static LONG convert_to_relative_position(int coordinate, int screen_size) {
// See https://stackoverflow.com/a/4555214 and its comments
Expand All @@ -73,7 +58,6 @@ static LONG convert_to_relative_position(int coordinate, int screen_size) {

static int map_keyboard_event(uiohook_event * const event, INPUT * const input) {
input->type = INPUT_KEYBOARD; // | KEYEVENTF_SCANCODE
//input->ki.wScan = event->data.keyboard.rawcode;
//input->ki.time = GetSystemTime();

switch (event->type) {
Expand All @@ -98,12 +82,10 @@ static int map_keyboard_event(uiohook_event * const event, INPUT * const input)
return UIOHOOK_FAILURE;
}

// FIXME Why is this checking MASK_SHIFT
if (event->mask & MASK_SHIFT) {
for (int i = 0; i < sizeof(extend_key_table) / sizeof(uint16_t)
&& input->ki.wVk == extend_key_table[i]; i++) {
input->ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
}
input->ki.wScan = MapVirtualKeyW(input->ki.wVk, MAPVK_VK_TO_VSC_EX);

if (HIBYTE(input->ki.wScan)) {
input->ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
}

return UIOHOOK_SUCCESS;
Expand Down

0 comments on commit b1e737d

Please sign in to comment.