ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have written a really ugly program in C that reads input from my gamepad and then generates xevents, or sends keycodes, whatever you wanna call it, using the Xtest library (#include <X11/extensions/XTest.h>). So that for example, when you press the X-button on the gamepad, I make X generate a "press return key event".
I read byte by byte from /dev/input/js0 and I figured that maybe all gamepads and joysticks haven't got the same output, so I wanted to use something generic to read joystick/gamepad input. Something like SDL maybe.
But I can't get SDL to read input when the SDL app window is passive. I rather not use a gui at all since I only want to launch a daemon that listens for gamepad inputs and then makes xevents.
Where's the code? Can't say why it is doing whatever it is doing without looking at the code. Make sure you wrap them in [code] tags to preserve indentation.
I have written a really ugly program in C that reads input from my gamepad and then generates xevents, or sends keycodes, whatever you wanna call it, using the Xtest library (#include <X11/extensions/XTest.h>). So that for example, when you press the X-button on the gamepad, I make X generate a "press return key event".
I read byte by byte from /dev/input/js0 and I figured that maybe all gamepads and joysticks haven't got the same output, so I wanted to use something generic to read joystick/gamepad input. Something like SDL maybe.
But I can't get SDL to read input when the SDL app window is passive. I rather not use a gui at all since I only want to launch a daemon that listens for gamepad inputs and then makes xevents.
If you are going to use linux, the /dev/input/jsX interfaces all generate the same sort of output, regardless of manufacturer (IIRC, joydev is the driver responsible for this). Why are you reading one byte at a time? You should read more bytes (maybe 8?). Whatever the number, it's probably better to use sizeof(whatever_the_js_event_struct_is_called) instead. It's been awhile, but I think upon the opening of the device, joydev spits out some stuff (i.e., fake events with special meaning) that's supposed to tell you about the number of buttons/axes/etc. on this specific joypad. There are also some IOCTL's to figure this out.
You can use the linux joydev API directly instead of trying to find a library with its own joystick API (unless, of course, you want some sort of cross-platform portability). Documentation should be in the linux source tree.
Yeah, I found out later on that using the js_event is probably the way to go. However, I can't seem to compile the program. Maybe you guys could help me.
I try to compile with "gcc test.c" but I get
‘js_event’ undeclared (first use in this function)
and I can't figure out what lib the #include <linux/joystick.h> whould be in.
What args should I have to gcc?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.