Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What kind of data is stored in the /DEV/MOUSE file, how do I read it?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Below is the code I use to get ANYTHING from the mouse, it does work and read in the data from the mouse, but it has no format, and is just garbage.
Example:
Left = "ÿûÿ¿ È"
Right = "ûÿ¿ È"
Left click is 3 line feeds.
I know its something simple but I am too new to find it, I have looked everywhere, but most open("/dev/mouse", O_RDWR); searches turn up load of useless .diff files.

Please help me if you can, I have been trying to figure it out for about 2 weeks.


#include "stdio.h"
#include "sys/types.h"
#include "unistd.h"
#include "fcntl.h"

void
main() {

int fd; /* file descriptor for the device */
char buff[16]; /* string of 16 bytes */

if ((fd = open(&quot;/dev/mouse&quot;, O_RDWR)) < 0) {
fprintf(stderr, &quot;Can't open: &quot;); perror(&quot;/dev/mouse&quot;); exit(1);
} else {
printf(&quot;/dev/mlouse opened with fd = %d\n&quot;, fd);
}

printf(&quot;size of buff is %d\n&quot;, sizeof(buff));
printf(&quot;read returns %d\n&quot;, read(fd, buff, sizeof(buff)));

buff[15] = 0; /* null terminate the string */

/* display the data read into the buffer */
printf(&quot;buff is:\n%s\n&quot;, buff);
close(fd);
}

All I really care about is direction and speed of the mouse going left to right, and the state change of the left button. I can't use libgpm, ncurses, or allegro, I just need those 3 things. I am using allegro now, but I need to not have x-windows running do to space requirements.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top