Advertisement
Guest User

houbysoftxfcz

a guest
Oct 25th, 2008
2,791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. void mouse_handler(struct regs *r)
  2. {
  3.   static unsigned char cycle = 0;
  4.   static char mouse_bytes[3];
  5.   mouse_bytes[cycle++] = inportb(0x60);
  6.  
  7.   if (cycle == 3) { // if we have all the 3 bytes...
  8.     cycle = 0; // reset the counter
  9.     // do what you wish with the bytes, this is just a sample
  10.     if ((mouse_bytes[0] & 0x80) || (mouse_bytes[0] & 0x40))
  11.       return; // the mouse only sends information about overflowing, do not care about it and return
  12.     if (!(mouse_bytes[0] & 0x20))
  13.       y |= 0xFFFFFF00; //delta-y is a negative value
  14.     if (!(mouse_bytes[0] & 0x10))
  15.       x |= 0xFFFFFF00; //delta-x is a negative value
  16.     if (mouse_bytes[0] & 0x4)
  17.       puts("Middle button is pressed!n");
  18.     if (mouse_bytes[0] & 0x2)
  19.       puts("Right button is pressed!n");
  20.     if (mouse_bytes[0] & 0x1)
  21.       puts("Left button is pressed!n");
  22.     // do what you want here, just replace the puts's to execute an action for each button
  23.     // to use the coordinate data, use mouse_bytes[1] for delta-x, and mouse_bytes[2] for delta-y
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement