Handling input in Linux

Started by
9 comments, last by BlackDeath3 11 years, 9 months ago
I'm about to begin work on the Linux portion of my input system. For keyboard/mouse input, I'm undecided if I should use XCB/Xlib or if I should use the kernel input directly (/dev/input/...). Does anyone have any experience as to which method is preferred? I would like to support joysticks and gamepads in the future as well. From what I've been reading, it seems I'll need to use the kernel input directly for those, so would it make sense to just use it for everything? The only thing I don't really like is the lack of permissions by default to open files in /dev/input, but that's easily solvable using groups.

Thanks
Advertisement
I would use X11 only. The X server can be configured to handle the input sources. And you have a uniform interface to everything concerning user interaction.
It may be that the glfw library gives you just what you want.
[size=2]Current project: Ephenation.
[size=2]Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/
It's unlikely that XInput will not give you everything you need, except maintenance headaches. The current version (XI2.2) support joysticks, gamepads, and multitouch devices. There are a few devices, like accelerameters and video capture, that may not work well through X, but they will not work any better if you try to handle them through the kernel event device interface, too.

If your game needs to run as root, you're definitely doing something wrong.

Stephen M. Webb
Professional Free Software Developer

Thanks for the input everyone. I guess I will use X, as least as far as it will take me, and if I do hit any limitations I may rethink the decision. Does XI2.2 support force feedback? That's the only limitation I'm really worried about at the moment.


If your game needs to run as root, you're definitely doing something wrong.

Well it wouldn't have to run as root if I create an input group and a udev rule, but that might be asking too much out of users.

Does XI2.2 support force feedback?

From what I can tell, XI2 does not support force feedback. Additionally, I haven't even been able to get XI2 to recognize the joystick as an input device. evtest and fftest work fine though. I found a bug report describing a similar problem, although that person was able to get the device to be recognized by modifying a configuration file. However, I did discover that joysticks (in /dev/input/eventX) can be used in user space, even though the mouse and keyboard cannot. I think my solution will be to have X handle the mouse/keyboard input, and use the eventX file for joysticks. I don't have any touch devices lying around, so I can't test those. I guess I'll cross that hurdle when I get to it.
I've been working with Xlib lately but I've just run into a problem with KeyPress and KeyRelease. It seems that KeyRelease either doesn't detect an actual key release and my program thinks a key is being held down when it's not, or it signals a false release, followed by a false press, ad nauseum. Has anyone else run into and overcome this problem? Should I try something other than Xlib? Any advice for yet another newbie-aspiring-to-be game programmer?
Try OIS
http://sourceforge.net/projects/wgois/

Try OIS
http://sourceforge.net/projects/wgois/


Thanks for the link! Judging by a quick look at the source, it seems as though OIS is built upon (at least to some extent) X11 and Xlib. I'll have to study this and hopefully gain some insight as to how they overcame the problem I've been having. Perhaps I can even craft my own input system after studying this.
Good luck :)

This topic is closed to new replies.

Advertisement