# include <stdio.h> # include <conio.h> # include <dos.h> const int InitMouse( ); void ShowMouseCursor( ); void HideMouseCursor( ); void SetMousePosition(int x,int y); void GetMousePosition(int *x,int *y); void SetMouseHorizontalRange(int x_min,int x_max); void SetMouseVerticalRange(int y_min,int y_max); void SetMouseRange(int x_min,int y_min,int x_max,int y_max); const int LeftMouseKeyPressed( ); const int RightMouseKeyPressed( ); void show_border( ); int main( ) { int x_cord; int y_cord; int prev_x_cord; int prev_y_cord; clrscr( ); textmode(BW80); if(!InitMouse( )) { printf(\"Fatal Error : Unable to detect the Mouse.\"); printf(\"\\nPress ANY key to exit...\"); getch( ); exit(1); } show_border( ); ShowMouseCursor( ); SetMousePosition(320,100); SetMouseRange(16,24,623,183); gotoxy(1,25); printf(\"Note: Press ANY key to exit.\"); do { GetMousePosition(&x_cord,&y_cord); if(x_cord!=prev_x_cord || y_cord!=prev_y_cord) { gotoxy(1,1); printf(\"Current Mouse Coordinates : ( x=%u , y=%u ) \",x_cord,y_cord); prev_x_cord=x_cord; prev_y_cord=y_cord; } if(LeftMouseKeyPressed( )) { gotoxy(1,2); printf(\"*** Left Mouse Key Pressed\"); while(LeftMouseKeyPressed( )); gotoxy(1,2); printf(\" \"); } if(RightMouseKeyPressed( )) { gotoxy(1,2); printf(\"*** Right Mouse Key Pressed\"); while(RightMouseKeyPressed( )); gotoxy(1,2); printf(\" \"); } } while(!kbhit( )); getch( ); return 0; } //-------------------------- show_border( ) ---------------------------// void show_border( ) { int i; gotoxy(2,3); printf(\"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\"); for(i=0;i<20;i++) { gotoxy(2,(4+i)); printf(\"º º\"); } gotoxy(2,24); printf(\"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\"); } //--------------------------- InitMouse( ) ----------------------------// const int InitMouse( ) { union REGS InReg; union REGS OutReg; InReg.x.ax=0x0000; int86(0x33,&InReg,&OutReg); if(OutReg.x.ax==0x0000 && OutReg.x.bx==0xFFFF) return 0; return 1; } //------------------------- ShowMouseCursor( ) ------------------------// void ShowMouseCursor( ) { union REGS InReg; union REGS OutReg; InReg.x.ax=0x0001; int86(0x33,&InReg,&OutReg); } //------------------------- HideMouseCursor( ) ------------------------// void HideMouseCursor( ) { union REGS InReg; union REGS OutReg; InReg.x.ax=0x0002; int86(0x33,&InReg,&OutReg); } //------------------------ SetMousePosition( ) ------------------------// void SetMousePosition(int x,int y) { union REGS InReg; union REGS OutReg; InReg.x.ax=0x0004; InReg.x.cx=x; InReg.x.dx=y; int86(0x33,&InReg,&OutReg); } //------------------------- GetMousePosition( ) -----------------------// void GetMousePosition(int *x,int *y) { union REGS InReg; union REGS OutReg; *x=0; *y=0; InReg.x.ax=0x0003; int86(0x33,&InReg,&OutReg); *x=OutReg.x.cx; *y=OutReg.x.dx; } //---------------------- SetMouseHorizontalRange( ) -------------------// void SetMouseHorizontalRange(int x_min,int x_max) { union REGS InReg; union REGS OutReg; InReg.x.ax=0x0007; InReg.x.cx=x_min; InReg.x.dx=x_max; int86(0x33,&InReg,&OutReg); } //---------------------- SetMouseVerticalRange( ) ---------------------// void SetMouseVerticalRange(int y_min,int y_max) { union REGS InReg; union REGS OutReg; InReg.x.ax=0x0008; InReg.x.cx=y_min; InReg.x.dx=y_max; int86(0x33,&InReg,&OutReg); } //-------------------------- SetMouseRange( ) -------------------------// void SetMouseRange(int x_min,int y_min,int x_max,int y_max) { SetMouseVerticalRange(y_min,y_max); SetMouseHorizontalRange(x_min,x_max); } //---------------------- LeftMouseKeyPressed( ) -----------------------// const int LeftMouseKeyPressed( ) { union REGS InReg; union REGS OutReg; InReg.x.ax=0x0003; int86(0x33,&InReg,&OutReg); return ((OutReg.x.bx==0x0001)?1:0); } //---------------------- RightMouseKeyPressed( ) ----------------------// const int RightMouseKeyPressed( ) { union REGS InReg; union REGS OutReg; InReg.x.ax=0x0003; int86(0x33,&InReg,&OutReg); return ((OutReg.x.bx==0x0002)?1:0); }