houmain/keymapper

Mouse stop to work on OSX Monterey

clyra opened this issue ยท 10 comments

Hi,

I'm running keymapperd 4.5.2-5-g56fa73e and as soon as I start it with "sudo keymapper-launchd add", my mouse stop to work and I have to do "sudo keymapper-launchd remove" to be able to see the pointer/use the mouse again. I tried to only grab the keyboard, but as per documentation, it only works on linux, right? So, the config below is useless:

@skip-device /.*/
@grab-device "Keyboard K380"

I do have a app called steermouse that add a couple of mouse mappings, but even disabling it, the mouse is lost when keymapper starts.

Yes, right the explicit grabbing is not implemented yet, but hopefully will be soon.
Currently the MacOS version only grabs devices which pretend to be keyboards.
Maybe this steermouse is still running but simply forwarding all input when disabled? And both applications are grabbing each other...

Hi,

Now, i dont think the problem is the steermouse aplication. I tried to run keymapperd on the terminal so I could see the logs, and this is what happened (also running keymapper on another terminal):

sudo keymapperd --verbose                                      
Password:
Waiting for keymapper to connect
ERROR: Accepting keymapper connection failed
Waiting for keymapper to connect
Resetting configuration
Active contexts received (1)
Updating device list
  'MX Anywhere 2S' ignored
  'Keyboard K380' ignored
  'Headset' ignored
Updating device list
  'MX Anywhere 2S' grabbed
  'Keyboard K380' grabbed
  'Headset' ignored
Creating virtual device 'Karabiner'
Karabiner connected
Entering update loop
Updating device list
  'MX Anywhere 2S' already grabbed
  'Keyboard K380' already grabbed
  'Headset' ignored
Updating device list
  'Karabiner DriverKit VirtualHIDKeyboard 1.7.0' ignored
  'MX Anywhere 2S' already grabbed
  'Keyboard K380' already grabbed
  'Headset' ignored
Connection to keymapper reset
Releasing all keys (1)
Resetting configuration
Ungrabbing all devices

It seems that keymapper is indeed grabing the mouse device "MX Anywhere 2S". btw, my config is simple as possible:

@skip-device /.*/
@grab-device "Keyboard K380"

CapsLock >> Shift
CapsLock{Any} >> (Shift Control Meta AltLeft){Any}

Thank you for the thorough report!
Mhh, strange.
This is the code in src\server\unix\GrabbedDevicesMacOS.cpp, grab_mice is currently unconditionally false:

  bool is_keyboard(IOHIDDeviceRef device) {
    return IOHIDDeviceConformsTo(device, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard);
  }

  bool is_mouse(IOHIDDeviceRef device) {
    return IOHIDDeviceConformsTo(device, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse);
  }

  bool is_supported_device(IOHIDDeviceRef device, bool grab_mice) {
    return (is_keyboard(device) || (grab_mice && is_mouse(device)));
  }

I searched for "IOHIDDeviceConformsTo mouse kHIDUsage_GD_Keyboard" and found this issue, which is likely the same problem the other way round. They have added an advice in their FAQ.
Maybe you can also patch the source for now and check the device name in line 207.

Hi

I may need some help... If I got it right, the problem is that the function is_keyboard returns true but the device is a mouse, right? So I should check something like device.name == "Keyboard K380" ?

I think adding a && name != "MX Anywhere 2S" should work. Since the mouse is pretending to be a keyboard.

grafik

hm... I guess we missed something in this "if". After applying this i got:

Updating device list
'MX Anywhere 2S' ignored
'Keyboard K380' ignored
'Karabiner DriverKit VirtualHIDKeyboard 1.7.0' grabbed
'Headset' ignored

Mhh, yeah maybe it's too late. This should also work:
grafik

Thanks,

Now it's working. Looking forward to see the explicit grabbing working.

I'm kind puzzled because it worked on one machine but not on the other. But i did a small tweak on this "if", and this seems to work better:

if (name.empty() || name.find("MX Anywhere") != std::string::npos)

Hi,
with the latest commit the grab/skip-device directives are available on MacOS.