ililim / dual-key-remap

Remap any key to any other two keys on Windows 🔥. Remap CapsLock to both Ctrl and Escape! (It's like xcape for windows!)
GNU General Public License v2.0
492 stars 35 forks source link

Use with Windows PowerToys #51

Open devnguy opened 2 years ago

devnguy commented 2 years ago

Hi,

I remapped my left alt key to left control and vice versa through Windows PowerToys. Now when using this project and pressing caps lock with other keys, it looks like alt is being registered instead of control.

Desired behavior: CTRL when pressed with other keys Observed behavior: ALT when pressed with other keys

I've tried these configs, but all have the same result

remap_key=CAPSLOCK
when_alone=ESCAPE
with_other=CTRL
remap_key=CAPSLOCK
when_alone=ESCAPE
with_other=RIGHT_CTRL
remap_key=CAPSLOCK
when_alone=ESCAPE
with_other=ALT

Is this project expected to work after remapping the control key through some other program?

ililim commented 1 year ago

Interesting. I haven't tested this configuration, so I assume that what happens depends on the order in which that different remapping softwares handle the keys. I can take a look.

lihz commented 1 year ago

PowerToys use 0x101 as INJECTION KEY. So, add or modify the key in dual-key-remap.c

Method 1 > add key.

define INJECTED_KEY_ID 0xFFC3CED7

define POWER_TOYS_INJECTED_KEY_ID 0x101

LRESULT CALLBACK keyboard_callback(int msg_code, WPARAM w_param, LPARAM l_param) { int block_input = 0;

// Per MS docs we should only act for HC_ACTION's
if (msg_code == HC_ACTION) {
    KBDLLHOOKSTRUCT * data = (KBDLLHOOKSTRUCT *)l_param;
    enum Direction direction = (w_param == WM_KEYDOWN || w_param == WM_SYSKEYDOWN)
        ? DOWN
        : UP;
    //int is_injected = data->dwExtraInfo == INJECTED_KEY_ID;
    int is_injected = (data->dwExtraInfo == INJECTED_KEY_ID || data->dwExtraInfo == POWER_TOYS_INJECTED_KEY_ID);

.... }

or Method 2 > just use key of PowerToys

define INJECTED_KEY_ID 0x101 // 0xFFC3CED7


and recompile dual-key-remap !

Limitation: Should excute dual-key-remap.exe AFTER PowerToys running.

PS:

LRESULT CALLBACK _keyboardcallback(int msg_code, WPARAM w_param, LPARAM l_param) { .... return (block_input) ? 1 : CallNextHookEx(g_mouse_hook, msg_code, w_param, l_param); } I think this line needs to be fixed with <g_keyboard_hook>.