iohook icon indicating copy to clipboard operation
iohook copied to clipboard

[OSX high sierra] Key- press/down/up is only called once

Open Mat-thieu opened this issue 5 years ago • 54 comments

Expected Behavior

Upon attaching key- press/down/up, the callback should be fired every time these events happen.

Current Behavior

The callback is only fired once

Possible Solution

No clue

Steps to Reproduce (for bugs)

const iohook = require('iohook');

iohook.on('keydown', event => {
  console.log(event);
});

iohook.start();

Your Environment

screen shot 2018-11-08 at 19 25 10 NodeJS: 10.11.0

Mat-thieu avatar Nov 08 '18 18:11 Mat-thieu

I can confirm this with node v8.11.4 (no electron)

kevinresol avatar Nov 17 '18 12:11 kevinresol

Hi there !

Thanks for your feedback. I can't reproduce this on Mojave. Will try a bit more tomorrow or later this week when I can.

Djiit avatar Nov 17 '18 18:11 Djiit

@Djiit Thanks! Good to know it's working on Mojave at least, it's probably time to update then. Before I do though, is there anything I can help you with regarding testing on High Sierra? I can place some console logs in the lib and share the results if that helps.

Mat-thieu avatar Nov 21 '18 11:11 Mat-thieu

I'm using only mouse events, but whenever I press a keyboard key, mouse events stop firing. I'm using MacOS High Sierra too.

emilevirus avatar Nov 23 '18 14:11 emilevirus

me too(in mojave 10.14.1).

my log
$ cat index.js 
const iohook = require("iohook")

iohook.on("keydown", e => {
	console.log("down", e)
})

iohook.on("keyup", e => {
	console.log("up", e)
})

iohook.start(true)
$ node index.js 
hook_run [1121]: Accessibility API is enabled.
hook_run [1172]: CGEventTapCreate Successful.
hook_run [1178]: CFMachPortCreateRunLoopSource successful.
hook_run [1183]: CFRunLoopGetCurrent successful.
hook_run [1196]: CFRunLoopObserverCreate successful.
dispatch_event [108]: Dispatching event type 1.
hook_enable [257]: Thread Result: (0).
process_mouse_moved [882]: Mouse moved to 725, 495.
dispatch_event [108]: Dispatching event type 9.
process_mouse_moved [882]: Mouse moved to 726, 495.
dispatch_event [108]: Dispatching event type 9.
process_mouse_moved [882]: Mouse moved to 728, 496.
dispatch_event [108]: Dispatching event type 9.
process_mouse_moved [882]: Mouse moved to 729, 497.
dispatch_event [108]: Dispatching event type 9.
process_mouse_moved [882]: Mouse moved to 730, 497.
dispatch_event [108]: Dispatching event type 9.
process_mouse_moved [882]: Mouse moved to 730, 497.
dispatch_event [108]: Dispatching event type 9.
process_mouse_moved [882]: Mouse moved to 730, 497.
dispatch_event [108]: Dispatching event type 9.
process_mouse_moved [882]: Mouse moved to 731, 497.
dispatch_event [108]: Dispatching event type 9.
process_key_pressed [367]: Key 0X1E pressed. (0)
dispatch_event [108]: Dispatching event type 4.
process_key_pressed [379]: Using dispatch_sync_f for key typed events.
down { shiftKey: false,
  altKey: false,
  ctrlKey: false,
  metaKey: false,
  keycode: 30,
  rawcode: 0,
  type: 'keydown' }
^C
$ node -v
v8.12.0
$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.1
BuildVersion:	18B75

rinsuki avatar Nov 23 '18 18:11 rinsuki

is it fixed?

qbright avatar Nov 27 '18 13:11 qbright

I can't reproduce this; and I'm on Mojave.

Djiit avatar Nov 27 '18 13:11 Djiit

I just ran into this issue on a fresh project identical to the example provided and I'm using Mojave.

Just running in a raw node app, no electron involved. Node v10.10.0

euroclydon37 avatar Dec 26 '18 22:12 euroclydon37

Running in debug mode and found out that it removes all callbacks. I was getting mouse events firing until a key was pressed. So I think this is a problem in the NodeHookAddon.

euroclydon37 avatar Dec 31 '18 22:12 euroclydon37

Does line 89 need a break;? I'm only vaguely familiar with any of the C languages. But if the key is not the escape key, this switch would fall through to the key release case, right?

https://github.com/wilix-team/iohook/blob/8233c8af806b0c811267a6515adfa06d41edd6a7/libuiohook/src/demo_hook.c#L67-L89

euroclydon37 avatar Dec 31 '18 22:12 euroclydon37

Hi, i have same issue. After first keydown event callbacks stop calling.

I'm on Mojave 10.14.2, node version 10.15.0.

const ioHook = require('iohook');

ioHook.start(true);

Here is debug output

hook_run [1121]: Accessibility API is enabled.
hook_run [1172]: CGEventTapCreate Successful.
hook_run [1178]: CFMachPortCreateRunLoopSource successful.
hook_run [1183]: CFRunLoopGetCurrent successful.
hook_run [1196]: CFRunLoopObserverCreate successful.
dispatch_event [108]: Dispatching event type 1.
hook_enable [257]: Thread Result: (0).
process_key_pressed [367]: Key 0X39 pressed. (0X31)
dispatch_event [108]: Dispatching event type 4.
process_key_pressed [379]: Using dispatch_sync_f for key typed events.
             ^C

I commented out this line and rebuilt the package.

I don't familiar with C, and don't know what this line does, but now all works fine.

I hoping this may be helpful

LastDreamer avatar Jan 03 '19 17:01 LastDreamer

Hi guys,

These file are part of libuiohook, the lib used by iohook. I suggest you open an issue there.

Le jeu. 3 janv. 2019 à 18:27, Oleg Kravchenko [email protected] a écrit :

Hi, i have same issue. After first keydown event callbacks stop calling.

I'm on Mojave 10.14.2, node version 10.15.0.

const ioHook = require('iohook');

ioHook.start(true);

Here is debug output

hook_run [1121]: Accessibility API is enabled. hook_run [1172]: CGEventTapCreate Successful. hook_run [1178]: CFMachPortCreateRunLoopSource successful. hook_run [1183]: CFRunLoopGetCurrent successful. hook_run [1196]: CFRunLoopObserverCreate successful. dispatch_event [108]: Dispatching event type 1. hook_enable [257]: Thread Result: (0). process_key_pressed [367]: Key 0X39 pressed. (0X31) dispatch_event [108]: Dispatching event type 4. process_key_pressed [379]: Using dispatch_sync_f for key typed events. ^C

I commented out this line https://github.com/wilix-team/iohook/blob/master/libuiohook/src/darwin/input_hook.c#L380 and rebuilt the package.

I don't familiar with C, and don't know what this line does, but now all works fine.

I hoping this may be helpful

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wilix-team/iohook/issues/124#issuecomment-451215897, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHZtKo8fbN0NGzFcUVHI4qMogCji2hUks5u_j2NgaJpZM4YVO8m .

Djiit avatar Jan 03 '19 18:01 Djiit

I also have this problem.

I followed LastDreamer's advice and commented-out the offending line. Everything now seems to be working.

Xen0phobe avatar Jan 28 '19 13:01 Xen0phobe

Hi, i have same issue. After first keydown event callbacks stop calling.

I'm on Mojave 10.14.2, node version 10.15.0.

const ioHook = require('iohook');

ioHook.start(true);

Here is debug output

hook_run [1121]: Accessibility API is enabled.
hook_run [1172]: CGEventTapCreate Successful.
hook_run [1178]: CFMachPortCreateRunLoopSource successful.
hook_run [1183]: CFRunLoopGetCurrent successful.
hook_run [1196]: CFRunLoopObserverCreate successful.
dispatch_event [108]: Dispatching event type 1.
hook_enable [257]: Thread Result: (0).
process_key_pressed [367]: Key 0X39 pressed. (0X31)
dispatch_event [108]: Dispatching event type 4.
process_key_pressed [379]: Using dispatch_sync_f for key typed events.
             ^C

I commented out this line and rebuilt the package.

I don't familiar with C, and don't know what this line does, but now all works fine.

I hoping this may be helpful

Can you tell me the detail steps to rebuild this? I comment out this line, and try to rebuild it. But I fail to do this. Thanks a lot !:>

random-yang avatar Feb 06 '19 01:02 random-yang

Also having this issue on Mac OS X 10.14.

Karric avatar Feb 06 '19 22:02 Karric

@LastDreamer - Can you provide your steps?

Karric avatar Feb 08 '19 17:02 Karric

@Djiit https://github.com/kwhat/libuiohook/issues/2 looks like they were having the issue, but then solved it

image

Perhaps this was a different issue though

MulverineX avatar Mar 24 '19 19:03 MulverineX

If it isn't, maybe this module has an outdated version of their code?

MulverineX avatar Mar 24 '19 19:03 MulverineX

@MulverineX - That thread is from 2014, I doubt iohook's dependency is that old.

@Djiit - Can you weight in on this?

Karric avatar Mar 27 '19 14:03 Karric

Hi there !

I can confirm we use libuiohook v1.1 so yes, we have this fix

Djiit avatar Mar 27 '19 14:03 Djiit

@Djiit - I'm using 'latest: 0.4.0' for iohook, and this 'fires-once' bug still persists on macOS Mojave. Do you have any recommendations? I would very much like to use this package.

Karric avatar Mar 27 '19 14:03 Karric

https://github.com/wilix-team/iohook/issues/124#issuecomment-450697095 this comment of any help/work?

MulverineX avatar Mar 27 '19 15:03 MulverineX

Just to confirm. Same problem on Mojave here

strifel avatar Apr 04 '19 18:04 strifel

Same problem on Mojave here +1

lymne avatar Apr 18 '19 07:04 lymne

on Mojave +1

andrewkuzmych avatar May 07 '19 17:05 andrewkuzmych

I can confirm this is still an issue (high sierra)

anthonywebb avatar May 09 '19 08:05 anthonywebb

Same here 🖐 Screenshot 2019-05-22 at 13 38 31

cupcakearmy avatar May 22 '19 11:05 cupcakearmy

Still have the problem there after a keydown mousemove stop his callback ! Some info : Capture d’écran 2019-06-05 à 13 33 21 Capture d’écran 2019-06-05 à 13 34 07

leon3s avatar Jun 05 '19 11:06 leon3s

I also have this problem, node 10.16.0 and mojaveOS 10.14.1

julia-suarez-deel avatar Jul 02 '19 18:07 julia-suarez-deel

Hi! I tried the solution explained in this comment https://github.com/wilix-team/iohook/issues/124#issuecomment-451215897 and it works! Thanks @LastDreamer

Not sure when this is going to be fixed but for now our team feels forced to make a fork of iohook until this is fixed, this bug is huge, it makes the library unusable in macOS.

See the steps to fix the library here:

  1. Clone iohook repository git clone https://github.com/wilix-team/iohook.git iohook
  2. Execute in terminal cd iohook
  3. Comment this line

Now you need to compile the library

  1. The library used to compile iohook is cmake-js so for example, if you want to build the library for NodeJS v10.16.0 (My case) You need to execute this: npx cmake-js compile -r node -v 10.16.0 BTW is useful to use the --help command to see the options of cmake-js like this npx cmake-js compile --help

After the compilation is completed look for the file build/Release/iohook.node, this is your compiled library, now you need to move it to your project. Look in <your_real_project>/node_modules/iohook/builds/ here you need to find the folder according to your platform and node version. For me, the folder name is node-v64-darwin-x64. The v64 is the ABI of the nodeJS version. If you want to find this folder more easily, in the documentation you can find a small script: https://wilix-team.github.io/iohook/manual-build.html

Just copy the script from the docs and run node script.js. The script will tell you the right name folder according to the node version you use to execute the script.

In few words, copy the repo, comment the line, rebuild, copy the compiled library to your real project in the real project and that's it.

Hope this helps you.

julia-suarez-deel avatar Jul 18 '19 23:07 julia-suarez-deel