home *** CD-ROM | disk | FTP | other *** search
- // MOUSETST.C - NOTE: This file was slightly modified.
- // left button turns cursor ON and OFF
- // right button end program
-
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
-
- #define LMB 1
- #define RMB 2
-
- int IsMouse(void);
- int MouseClick(void);
- void MouseXY(int *xpos,int *ypos);
- void MouseShow(int YesNo);
-
- union REGS inregs;
- union REGS outregs;
-
- void main() {
- int xpos, ypos, xold=0, yold=0, btn, flag=1;
-
- clrscr();
- btn = IsMouse();
- if(!btn) {
- printf("Mouse Driver Not Installed!\n");
- exit(1);
- }
- gotoxy(1,1);
- printf("There are %d buttons on this mouse",btn);
- //getch();
- //clrscr();
- MouseShow(flag);
- do {
- MouseXY(&xpos,&ypos);
- if ((xold != xpos) || (yold != ypos)) {
- gotoxy(1,2);
- printf("x = %d y = %d ",xpos,ypos);
- }
- xold = xpos;
- yold = ypos;
- btn = MouseClick();
- if (btn == LMB) {
- if (flag) flag = 0;
- else flag = 1;
- MouseShow(flag);
- }
- }while(btn != RMB);
-
- }
-
-
- int IsMouse(void)
- {
- inregs.x.ax = 0;
- int86(0x33,&inregs,&outregs);
- return(outregs.x.ax ? outregs.x.bx : 0);
- }
-
- int MouseClick(void)
- {
- int click = 0;
- inregs.x.ax = 5;
- inregs.x.bx = 1;
- int86(0x33,&inregs,&outregs);
- click = outregs.x.bx << 1;
- inregs.x.bx--;
- int86(0x33,&inregs,&outregs);
- return(click | outregs.x.bx);
- }
-
- void MouseXY(int *xpos,int *ypos)
- {
- inregs.x.ax = 3;
- int86(0x33,&inregs,&outregs);
- *xpos = outregs.x.cx;
- *ypos = outregs.x.dx;
- }
-
-
- void MouseShow(int YesNo)
- {
- if (YesNo) inregs.x.ax = 1;
- else inregs.x.ax = 2;
- int86(0x33,&inregs,&outregs);
- }
-