Sign in to follow this  

Handling input in Linux

This topic is 1988 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

[quote name='Bregma' timestamp='1339617689' post='4948911']
If your game needs to run as root, you're definitely doing something wrong.
[/quote]
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.

Share this post


Link to post
Share on other sites
[quote name='njpaul' timestamp='1339676254' post='4949128']
Does XI2.2 support force feedback?
[/quote]
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 [url="https://bugs.freedesktop.org/show_bug.cgi?id=42399"]bug report[/url] 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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[quote name='themean' timestamp='1341343549' post='4955418']
Try OIS
[url="http://sourceforge.net/projects/wgois/"]http://sourceforge.net/projects/wgois/[/url]
[/quote]

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.

Share this post


Link to post
Share on other sites
[quote name='themean' timestamp='1341658223' post='4956612']
Good luck [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/quote]

So... it turns out that a solution I put into place several days ago, one that didn't seem to work, would have worked had I not made the ultra-noob mistake of forgetting to set all of my XSelectInput masks. Fail! At least it's working now, and I can move on to other problems. Thanks again for the link and the help!

Share this post


Link to post
Share on other sites

This topic is 1988 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this