reading joystick info
Jonathan B. York
jbyork at iglou.com
Sun Jul 16 00:22:33 EDT 2000
Hi,
I have a simple little C program that gets the "name" of the device at
/dev/js0. I would like to know if it is possible to do this in Python.
I've seen that there is code for joysticks with PySDL, but I just want
this simple function and don't want to bother with all that.
This is what the C program does:
#include <sys/ioctl.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/joystick.h>
#define NAME_LENGTH 128
int main (int argc, char **argv)
{
int fd;
char name[NAME_LENGTH] = "Unknown";
if ((fd = open(argv[argc - 1], O_RDONLY)) < O) {
perror("jstest");
exit(1);
}
ioctl(fd, JSIOCGNAME(NAME_LENGTH), name);
printf("Joystick -> %s", name);
}
If anyone has any advice, I'd really appreciate it. :)
Thanks in advance,
jonathan
More information about the Python-list
mailing list