SnosMe / uiohook-napi

MIT License
162 stars 37 forks source link

Missing keypress #16

Closed michelvermeulen closed 1 year ago

michelvermeulen commented 1 year ago

Hi!

Thanks for working on this. One thing I'm missing from the original iohook implementation is the keypress event which contains a "keychar" property that allows to transform a keycode into its matching key. I tried using the UiohookKey import but it doesn't work with the / key for instance (52 vs 53).

Do you have any insight on this?

SnosMe commented 1 year ago

I intentionally don't expose this in events, interpreting keycodes into actual characters according to KB layout is gray area of keyloggers. Adding them back is really trivial, you can do it in fork.

michelvermeulen commented 1 year ago

Hi Snos. Thanks for your reply. Still struggling with that, and I have no idea how to add them back although it looks really trivial. Could you help me out here?

SnosMe commented 1 year ago

Here I'm exposing only keycode

https://github.com/SnosMe/uiohook-napi/blob/63745a540828de230392eee3e6cf85d8a4d09e13/src/lib/addon.c#L61-L62

But you can add another js property with keychar

https://github.com/kwhat/libuiohook/blob/d60dc93e510c35cac8c09dcc982bbb55aad59222/include/uiohook.h#L91

You may also need to uncomment this

https://github.com/SnosMe/uiohook-napi/blob/63745a540828de230392eee3e6cf85d8a4d09e13/src/lib/uiohook_worker.c#L68

michelvermeulen commented 1 year ago

Thanks a lot! I'll try to get by with that info, I'm really not familiar with C so I'll fiddle around. Thanks again, I'll reach back if I can't work this out, happy to sponsor you at a personal level if I need more help :)

michelvermeulen commented 1 year ago

I guess I'll have to rebuild it to see changes after I change the source files?

michelvermeulen commented 1 year ago

Alright @SnosMe, I'm almost there. I added the keychar, but the value is different from what ioHook sends (ioHook sends 113 for q on my keyboard while uiohook always sends 65535.

This is what I added:

napi_value e_keychar;
status = napi_create_uint32(env, event->data.keyboard.keychar, &e_keychar);
NAPI_FATAL_IF_FAILED(status, "uiohook_to_js_event", "napi_create_uint32");
SnosMe commented 1 year ago

If you uncommented line I've mentioned, and added new if block with that event type, then idk

https://github.com/SnosMe/uiohook-napi/blob/63745a540828de230392eee3e6cf85d8a4d09e13/src/lib/addon.c#L60

Oh, also if you apply my patch I remove that code for some reason 😅

https://github.com/SnosMe/uiohook-napi/blob/63745a540828de230392eee3e6cf85d8a4d09e13/src/libuiohook.patch#L148-L174

michelvermeulen commented 1 year ago

I actually don't have the patch. I did everything yes, I do have warnings when doing node-gyp build:

  CC(target) Release/obj.target/uiohook_napi/src/lib/addon.o
../src/lib/addon.c:305:53: warning: passing 'int32_t *' (aka 'int *') to parameter of type 'uint32_t *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
  status = napi_get_value_uint32(env, info_argv[1], (int32_t*)&tap_type);
                                                    ^~~~~~~~~~~~~~~~~~~
/Users/michel/Library/Caches/node-gyp/18.12.1/include/node/js_native_api.h:140:68: note: passing argument to parameter 'result' here
                                                         uint32_t* result);
michelvermeulen commented 1 year ago

What's weird is the keychar is always the same value no matter which key I press: 65535

michelvermeulen commented 1 year ago

Alright, trying to help here, but I saw CHAR_UNDEFINED in some of the source files:

CleanShot 2022-12-05 at 21 58 17

If I change this value to a fixed number, it works, BUT I don't know how to get the keychar there :|

SnosMe commented 1 year ago

from this code it looks like keycode and keychar are swapped on macOS in uiohook 😄 or is it you changing code to debug it