houmain / keymapper

A cross-platform context-aware key remapper.
GNU General Public License v3.0
260 stars 22 forks source link

Feature Request: Input device aware mapping (macro keyboard support) #4

Closed G-M0N3Y-2503 closed 2 years ago

G-M0N3Y-2503 commented 3 years ago

For my use case, I have a "Razer Naga" that has a numeric keypad on the side which maps to the keys of the number row on a standard US keyboard layout. This means In order to configure key mappings for the mouse keypad and not the number row on a keyboard there would have to be some way to filter the input expressions to a particular device.

From a configuration point of view, a device filter for the context block might work.

[device="Razer Naga"]
Digit0 >> AltLeft ArrowLeft

However, that wouldn't work if someone else wanted a more powerful/flexible variation of this, where they might want to filter only parts of the input expression to a particular device.

G-M0N3Y-2503 commented 3 years ago

Otherwise, great work, this project looks almost perfect for my needs.
If this is something that you think would be amenable for this project (and I can find the motivation to jump back into C++ again) I might be able to help out with it.

houmain commented 3 years ago

Thank you for your appreciation! Your proposed addition to the context filters looks fine to me. That would be a nice feature to have, but also quite a bit of work. On Linux the most laborious part would be to get the configuration to the daemon and on Windows usage of this feature would presumably require enabling the Interception library (https://github.com/houmain/keymapper#windows) to get information about the triggering device. I am not sure when I would try implementing this (I might need some more use cases/votes).

houmain commented 2 years ago

Hi, this is now testable. There is a 2.1.0 release, which is currently still a "Pre-release". The feature is currently only available on Linux and the syntax is just as you proposed.

G-M0N3Y-2503 commented 2 years ago

That's awesome, I'll have to check this out again!

houmain commented 2 years ago

Fine! You should get the required exact device name using: cat /proc/bus/input/devices | grep Name= or by activating verbose output, by passing -v to keymapperd.

G-M0N3Y-2503 commented 2 years ago

Was just trying this out today and I noticed that the device that is used when one isn't specified was my mouse rather than my keyboard or both. This was somewhat unexpected to me, perhaps documenting the default device selection would mitigate this confusion for others?

Otherwise, I would have thought that mappings with unspecified devices would match all devices. That is, with 1 >> 9, 1 would map to 9 on all keyboards and mice.

G-M0N3Y-2503 commented 2 years ago

Actually, With the following config

[device="Razer Razer BlackWidow Ultimate 2013"]
1 >> 9
9 >> 1

[device="Razer Razer Naga 2014"]
1 >> 9
9 >> 1

Only the Naga had key mapping, neither the Numrow nor Numpad was mapped on the BlackWidow.

here is some extra info if that helps: Version: 2.1.2 from AUR

$ keymapperd --verbose
Waiting for keymapper to connect
Received configuration
Received contexts (2)
Creating uinput device 'Keymapper'
Updating device list
Grabbing device event3 'Razer Razer BlackWidow Ultimate 2013'
Grabbing device event9 'Razer Razer Naga 2014'
Entering update loop
Received contexts (2)
Received contexts (2)
Connection to keymapper reset
Ungrabbing device event3
Ungrabbing device event9
---------------
$ keymapper --verbose --update
Loading configuration file '/home/gerard/keymapper.conf'
Connecting to keymapperd
Sending configuration
Initializing focused window detection
Initialized X11 focused window detection
Initialized D-BUS focused window detection
Entering update loop
Detected focused window changed:
class = 'konsole'
title = '~ : bash — Konsole'
Detected focused window changed:
class = 'konsole'
title = '~ : keymapper — Konsole'
G-M0N3Y-2503 commented 2 years ago

I found the cause for this It seems that the wrong uinput device is used by keymapper. Sorry for the noise, this looks more like https://github.com/houmain/keymapper/issues/29 now.

lrwxrwxrwx 1 root root 9 Jun 18 20:09 /dev/input/by-id/usb-Razer_Razer_BlackWidow_Ultimate_2013-event-kbd -> ../event3
lrwxrwxrwx 1 root root 9 Jun 18 20:09 /dev/input/by-id/usb-Razer_Razer_BlackWidow_Ultimate_2013-if01-event-kbd -> ../event4
lrwxrwxrwx 1 root root 9 Jun 18 20:09 /dev/input/by-id/usb-Razer_Razer_BlackWidow_Ultimate_2013-if02-event-mouse -> ../event6
lrwxrwxrwx 1 root root 9 Jun 18 20:09 /dev/input/by-id/usb-Razer_Razer_BlackWidow_Ultimate_2013-if02-mouse -> ../mouse0

The device that outputs the events for me is the if01-event-kbd one.

G-M0N3Y-2503 commented 1 year ago

I was looking at the Win32 Raw Input Overview and it looks like you can get a device name with GetRawInputDeviceInfoA and map it to raw inputs. Might not be worth the effort for this in windows still, I was curious and just had a breif look.