Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read from multiple inputs #596

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

IzumiRaine
Copy link

Hacky implementation of multiple inputs on Linux.

My goal was to use extra buttons on my mouse to switch layers on my keyboard, so I needed a way to attach the same kmonad instance to two input devices. Unfortunately, it turns out the mouse pointer stops moving if I run kmonad on the mouse; so I abandonded the idea (I thought the keyboard and mouse parts would be different endpoints, but apparently not). Maybe this code can still be useful for somebody else as a starting point.

@jtroo
Copy link

jtroo commented Jul 23, 2022

the mouse pointer stops moving if I run kmonad on the mouse

Without having looked into the code specifics, I think this is fixable by forwarding all received events that kmonad doesn't care to process to uinput.

There may be some extra code that needs to be added to uinput registration for the kernel to accept kmonad's forwarded mouse events, though I'm not sure about that.

@MuhammedZakir
Copy link
Contributor

MuhammedZakir commented Jul 23, 2022

the mouse pointer stops moving if I run kmonad on the mouse

Without having looked into the code specifics, I think this is fixable by forwarding all received events that kmonad doesn't care to process to uinput.

Yes.

There may be some extra code that needs to be added to uinput registration for the kernel to accept kmonad's forwarded mouse events, though I'm not sure about that.

If I understand correctly, in this line [1], changing 256 to 275[2] should allow sending events for commonly used mouse buttons.

Edit: You may also add EV_REL events. See https://www.kernel.org/doc/html/latest/input/uinput.html#mouse-movements. For the "keycodes", search for REL in the header file [2].

Edit-2: I don't know if we can create a virtual device that sends both mouse and keyboard events. The ones I have seen uses different virtual devices. Edit: I remember seeing somewhere about using seperate event devices for keyboard and mouse events to prevent X from recognizing the virtual device as mouse. I don't know why that would cause a problem though.

Edit-3: This maybe helpful: https://www.kernel.org/doc/html/latest/input/event-codes.html

[1]

for (i=0; i < 256; i++) {

[2] These are keycodes; see /usr/include/linux/input-event-codes.h.

@slotThe
Copy link
Member

slotThe commented Aug 11, 2022

@IzumiRaine any updates on this?

@IzumiRaine
Copy link
Author

Sorry, nothing yet. I'll take another look around October (will be a bit too busy before then). Feel free to close the PR meanwhile.

@Ninlives
Copy link

@IzumiRaine Hi, could you please present a small configuration example of how to use multiple inputs? Thanks!

@IzumiRaine
Copy link
Author

@Ninlives sure. You can add multiple paths to device-file like this:

(defcfg
  input  (device-file "/dev/input/by-id/keyboard1" "/dev/input/by-id/keyboard2")
  output (uinput-sink "My KMonad output" "")
)

But please keep in mind that so far this is just a quick hack and only for Linux.

@stevep99
Copy link
Contributor

stevep99 commented Apr 26, 2024

+1 on this feature.

It would be nice as well if you could specify "*" as the input device, and then it would match all attached keyboard devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants