r/C_Programming • u/Stickhtot • Jun 03 '26
Question Get ALL keyboard input from Linux?
I'm currently making a program where when a key is pressed on any window or screen, a specific action happens, right now I am reading from /dev/input/event with open() but the problem is
- It only reads from a very specific device
- It doesn't read from all "keyboards" that I have (I have a laptop keyboard and a wired keyboard) and
- Sometimes the main keyboard that I use will just switch up it's number and I have to recompile the thing again
Is there a way to just conveniently get all keyboard input without all this hassle?
10
Upvotes
View all comments
Show parent comment
1
u/bigtoaster64 Jun 05 '26
I created for myself a little macro for a game, and on wayland you can get inputs basically only from udev, but you have to discover the devices yourself. But to "do" something with the keystrokes you get you indeed need to be focused (by the user) on the target window. And for my use case (a game) it was running under xwayland, so that's the only reason it worked (easily), but I also had to translate the keystrokes for some reason, x11 and wayland seem to not use the same codes...