robotn / gohook

GoHook, Go global keyboard and mouse listener hook
MIT License
314 stars 44 forks source link

Indecisive keycodes, keychar, rawcode #44

Open M1ndo opened 11 months ago

M1ndo commented 11 months ago

I've came across a really annoying bug. is that some keys like ctrl, alt, tab, shift, home, end ,delete, caps_lock keys, functions keys are not recognized and display the wrong keycode, keychar, rawcode.

In the following screenshot you can see, we're not able to obtain the correct keychar/rawcode for ctrl, alt, win key (as an example) are display unrecognized rawcode image You can also notice that Keycode is 0 in KeyDown event. In Another example we can see the difference clearly. that the rawcode is totally undefined. image I've searched around the code and couldn't exactly find where these codes are coming from. One other issue i've spotted is that some keys might have the correct keychar but wrong Rawcode like escape, backspace, enter on keydown event but on up event is not even correct. image Here's a list of undefined keys and their respective rawcode. Ctrl Left :: 65507 // Ctrl Right :: 65508 Windows/Meta Key :: 65515 Alt key :: 65513 // Alt Key Right 65514 Left shift :: 65505 // Right shift :: 65506 Caps Lock :: 65509 // Num Lock :: 65407 F1 :: 65470 // F2 :: 65471 F3 :: 65472 // F4 :: 65473 F5 :: 65474 // F6 :: 65475 F7 :: 65476 // F8 :: 65477 F9 :: 65478 // F10 :: 65479 F11 :: 65480 // F12 :: 65481 Delete :: 65535 // Insert :: 65379 End :: 65367 // Home :: 65360 Page Down :: 65366 // Page Up :: 65365

This issue on windows doesn't exist (sort of) All these keys i've tried worked except CTRL (L 162 / R 163) , ALT (L 164 / R 165) , SHIFT (L 160 / R 161)

M1ndo commented 11 months ago

I have created a workaround this issue for both Windows/Linux here maybe it be useful for you to fix it. Just to elaborate little bit, using my workaround works pretty well and translating keycodes works exactly it supposed to be. I'm not sure about darwin or existing of this issue in the, so its probably a good idea to investigate it .