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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I can read /DEV/MOUSE, but I cant find any good info on the offsets.

Status
Not open for further replies.

CNewbie

Programmer
Dec 20, 2001
18
0
0
US
I need to know where to read in the data of the mouse, and where to write the init data for my PS2 mouse, the offests Im using seem to be almost right but the data is not reliable.



#include <stdio.h>
#include <math.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/fcntl.h>
#include &quot;stdio.h&quot;
#include &quot;unistd.h&quot;
#include <sys/ioctl.h>


#define MOUSEDEV &quot;/dev/mouse&quot;
char button;
int mx, my;
int mouse;
int mousebuf[3];
int mousep = 0;

//opening the character device file
int openmouse()
{
mouse = open(MOUSEDEV,O_RDONLY);
if (mouse < 0) printf(&quot;Can't open mouse&quot;);
fcntl(mouse, F_SETFL, FNDELAY); /* set non-blocking i/o */
return 0;
}

//closing it
int closemouse()
{
close(mouse);
return 0;
}

//function for reading the file
int getinput(button,mx,my)
{
while (read(mouse, mousebuf, 256) == 1)
{
if ((mousebuf[0] & 0xc0)) return 0;
if (!(mousebuf[0] & 0x08)) return 0;

//just code to see the change after moving the mouse
do{printf(&quot;|%d=%d|&quot;,mousep,(mousebuf[0] & mousep));mousep++;}while (mousep <33);
mousep=0;
printf(&quot;\n&quot;);

//code to pick the data I need out of the character file, but the offsets are wrong, so im lost.

if (!(mousebuf[0] & 02)) button='r';
else if (!(mousebuf[0] & 04)) button='m';
else if (!(mousebuf[0] & 01)) button='l';
//printf(&quot;b=%d|\n&quot;,button);
mx = ( mousebuf[0] & 0x10) ? mousebuf[1]-256 : mousebuf[1];
//printf(&quot;x=%d|\n&quot;,mx);
my = ( mousebuf[0] & 0x20) ? -(mousebuf[2]-256) : mousebuf[2];
//printf(&quot;y=%d|\n&quot;,my);
}
return 0;
}

//code for reading in a mouse click, wont work until im reading the right data of course
char getclick()
{
char button;
int mx,my;
do
{
button = '\0';
getinput(&button,&mx,&my);
}while ( (button != 'l') && (button != 'm') && (button != 'r') );
return (button);
}

This example is using the /DEV/MOUSE character file for reading the mouse, I could try reaing the low-level port info, but again I'm unsure of where to read and right.

If someone can tell me where my mistakes are, or post some SIMPLE code for reading the mouse out of x-windows, with no gpm, or allegro, I would be very thankful.

I have been looking everywhere for a mini-how-to, or a man page for this info, but it doesn't seem to exist, the serial how-to, is for the serial port, and the data is all wrong, the usb-mouse how-to is the same way, and the 3-button one focuses on changing the kernel, and isn't real specific on whats going on where, its just a ,fill in the blanks, kind of thing.

I know its out there somewhere, but I cant find it, and the things I have found are parts of huge programing libraries, which makes it hard to track down whats going on and where.

I have been tring for 2 weeks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top