osx-mouse
osx-mouse copied to clipboard
Does not work with macOS Mojave 10.14
With latest master (247d83e
, tag: v1.3.1
), running the tests + moving the mouse fails to produce any output unlike prior version of macOS 10.13.
I've been unable to find a workaround, other than manually asking for accessibility permissions which according to Apple shouldn't be necessary for "listenOnly" taps.
Output when running test and moving mouse:
11:29:14 ~/jobs/osx-mouse ⚡️ yarn test
yarn run v1.10.1
$ node test/parallel-destroy && node test/parallel-unref && node test/sequence-destroy && node test/sequence-unref
destroy_1
destroy_2
unref_1
unref_2
destroy_1
destroy_2
unref_1
unref_2
✨ Done in 8.45s.
Output when giving full access via "accessibility" (to Terminal.app which I'm running the command through):
11:30:36 ~/jobs/osx-mouse ⚡️ yarn test
yarn run v1.10.1
$ node test/parallel-destroy && node test/parallel-unref && node test/sequence-destroy && node test/sequence-unref
move_2 710.3046875 539.0625
move_2 718.83984375 264.81640625
move_2 720.46484375 265.546875
move_2 722.171875 269.61328125
move_2 724.04296875 273.67578125
(...)
Adding accessibility permissions to the app using it remedies the problem. @kapetan is this to be expected?
I switched to using the Cocoa/NSEvent monitor API (as opposed to CGEventTap) in my fork. That works fine without accessibility permissions, but it has one difference. When the app window is focused, move
events will be received for the entire screen. When the app window is not focused, move
events will only be received when the cursor is over one of the app windows. Other events will not be received when the app window is not focused.
@kapetan Would you be interested in a PR that adds the NSEvent implementation as an alternative? Maybe we could have something like require('osx-mouse')({ mode: 'nsevent' | 'cgeventtap' })
. Or perhaps the module could even check for accessibility permissions and fall back to the NSEvent API on Mojave.
Here is my fork as a npm module: https://www.npmjs.com/package/osx-mouse-cocoa
Calling CGEventTapCreate will cause the system to be stuck, but will not fail. ^_^||
Nice work @poiru. Maybe it makes sense to merge it into this module, I'll have a look when I find the time. But for now I'm happy with it being a separate module.