# include # include # include # include //////////////////////////////////////////////////////////////////////////////////// union REGS regs; //////////////////////////////////////////////////////////////////////////////////// void draw_screen(void); void show_mouse(void); void initialize_mouse(void); void hide_mouse(void); void get_mouse_data(void); void set_mouse_pos(int xpos, int ypos); void set_mouse_horizontal_minmax(int xmin, int xmax); void set_mouse_vertical_minmax(int ymin, int ymax); void set_mouse_ratio(int x_ratio, int y_ratio); void restrict_mouse(int xpmin, int ypmin, int xpmax, int ypmax); void free_mouse_in_text_mode(void); //////////////////////////////////////////////////////////////////////////////// void main(void) { char buffer[3]; int x,y; draw_screen(); //only initializes the mouse but don't //show its pointer on the screen. initialize_mouse(); //shows the mouse pointer on the screen //if U don't include this statement in //the code then mouse will work even though //it is not visible. show_mouse();// restrict_mouse(1, 1, 78, 22); do{ //call to mouse interrupt to //get the current status of //the mouse until you quit. get_mouse_data(); //shows the mouse coordinates at //down right portion of screen. gotoxy(55, 24);cprintf("%2d", ((regs.x.cx)/8)); gotoxy(62, 24);cprintf("%2d", ((regs.x.dx)/8)); //if none of the mouse button is clicked ??? if((regs.x.bx)==0) { gotoxy(36, 24);cprintf("None "); }//end of if mouse left button is clicked //check else if mouse left button is clicked ??? else if((regs.x.bx)==1) { hide_mouse(); textcolor(random(16)); gotoxy((regs.x.cx/8)+1, (regs.x.dx/8)+1); cprintf("Û"); show_mouse(); textcolor(15); gotoxy(36, 24);cprintf("Left "); delay(10);//wait for a movement }//end of if mouse left button is clicked //check else if mouse right button is clicked ??? else if((regs.x.bx)==2) { hide_mouse(); textcolor(0); gotoxy((regs.x.cx/8)+1, (regs.x.dx/8)+1); cprintf("Û"); show_mouse(); textcolor(15); gotoxy(36, 24);cprintf("Right"); delay(10);//wait for a movement }//end of if mouse right button is clicked //check else if both mouse buttons are clicked ??? else if((regs.x.bx)==3) { gotoxy(36, 24);cprintf("Both "); delay(10);//wait for a movement }//end of if both mouse buttons are clicked }while(!kbhit());//loop goes on until a key is pressed //before quitting you //should hide the mouse. hide_mouse(); }//end of main program /* draw_screen(); show_mouse(); initialize_mouse(); restrict_mouse(1, 1, 78, 22); do{ //call to mouse interrupt to //get the current status of //the mouse until you quit. get_mouse_data(); //shows the mouse coordinates at //down right portion of screen. gotoxy(55, 24);cprintf("%2d", ((regs.x.cx)/8)); gotoxy(62, 24);cprintf("%2d", ((regs.x.dx)/8)); //if none of the mouse button is clicked ??? if((regs.x.bx)==0) { gotoxy(36, 24);cprintf("None "); }//end of if mouse left button is clicked //check else if mouse left button is clicked ??? else if((regs.x.bx)==1) { hide_mouse(); textcolor(random(16)); gotoxy((regs.x.cx/8)+1, (regs.x.dx/8)+1); cprintf("Û"); show_mouse(); textcolor(15); gotoxy(36, 24);cprintf("Left "); delay(10);//wait for a movement }//end of if mouse left button is clicked //check else if mouse right button is clicked ??? else if((regs.x.bx)==2) { hide_mouse(); textcolor(0); gotoxy((regs.x.cx/8)+1, (regs.x.dx/8)+1); cprintf("Û"); show_mouse(); textcolor(15); gotoxy(36, 24);cprintf("Right"); delay(10);//wait for a movement }//end of if mouse right button is clicked //check else if both mouse buttons are clicked ??? else if((regs.x.bx)==3) { gotoxy(36, 24);cprintf("Both "); delay(10);//wait for a movement }//end of if both mouse buttons are clicked }while(!kbhit());//loop goes on until a key is pressed //before quitting you //should hide the mouse. hide_mouse(); }//end of main program hide_mouse; get_mouse_data; set_mouse_pos; set_mouse_horizontal_minmax; set_mouse_vertical_minmax; set_mouse_ratio; free_mouse_in_text_mode; getch(); } */ ///////////////////////////////////////////////////////////////////////////// void draw_screen(void) { textbackground(0); clrscr(); textcolor(15); textbackground(4); cprintf(" Sample Program For Mouse Interface In C/C++ "); textcolor(14); cprintf("By: Muhammad Uneeb Walayat"); textcolor(15); for(short int r = 1; r<=23; r++) { for(short int c = 1; c<=80; c+=79) { gotoxy(c, r); cprintf(" "); } } gotoxy(1, 24); cprintf(" Button Click = None (x= , y= ) "); }//end of draw_screen() ////////////////////////////////////////////////////////////////////////////////////////// void initialize_mouse(void) { //for initializing the mouse // - place value 0 in AX register. // - call the mouse interrupt. regs.x.ax = 0; int86(0x33, ®s, ®s); //if mouse driver is not installed //then prompt the error message. if(regs.x.ax==0) { textbackground(0); clrscr(); printf("\nMouse Driver not installed."); printf("\nPress any key to exit the program ..."); getch();//keep the message on the screen until any key is pressed exit(1);//terminates the program }//if mouse driver is not installed }//end of initialize_mouse ////////////////////////////////////////////////////////////////////////////////////// void show_mouse(void) { //for showing the mouse // - place value 1 in AX register. // - call the mouse interrupt. regs.x.ax = 1 ; int86(0x33, ®s, ®s); }//end of show_mouse ////////////////////////////////////////////////////////////////////////////////////// void hide_mouse(void) { //for hiding the mouse // - place value 2 in AX register. // - call the mouse interrupt. regs.x.ax = 2 ; int86(0x33, ®s, ®s); }//end of hide_mouse ////////////////////////////////////////////////////////////////////////////////////// void get_mouse_data(void) { //for getting the mouse data // - place value 3 in AX register. // - call the mouse interrupt. regs.x.ax = 3; int86(0x33, ®s, ®s); }//end of get_mouse_data ////////////////////////////////////////////////////////////////////////////////////// void set_mouse_pos(int xpos, int ypos) { //for setting mouse to a particular place // - place value 4 in AX register. // - place new x location in CX register. // - place new y location in DX register. // - call the mouse interrupt. regs.x.ax = 4; regs.x.cx = xpos*8; //multiply by 8 to adjust for the mouse driver regs.x.dx = ypos*8; //multiply by 8 to adjust for the mouse driver int86(0x33, ®s, ®s); }//end of set_mouse_pos ////////////////////////////////////////////////////////////////////////////////////// void set_mouse_horizontal_minmax(int xmin, int xmax) { //for setting mouse horizontal limits //the mouse will move in the specified //region only and not beyond that unless //and until you free it by calling the //free function given below(each for TXT and GRPH.) // - place value 7 in AX register. // - place x minimum value in CX register. // - place x maximum value in DX register. // - call the mouse interrupt. regs.x.ax = 7; regs.x.cx = xmin*8; //multiply by 8 to adjust for the mouse driver regs.x.dx = xmax*8; //multiply by 8 to adjust for the mouse driver int86(0x33, ®s, ®s); }//end of set_mouse_horizontal_minmax ////////////////////////////////////////////////////////////////////////////////////// void set_mouse_vertical_minmax(int ymin, int ymax) { //for setting mouse vertical limits //the mouse will move in the specified //region only and not beyond that unless //and until you free it by calling the //free function given below(each for TXT and GRPH.) // - place value 8 in AX register. // - place y minimum value in CX register. // - place y maximum value in DX register. // - call the mouse interrupt. regs.x.ax = 8; regs.x.cx = ymin*8; //multiply by 8 to adjust for the mouse driver regs.x.dx = ymax*8; //multiply by 8 to adjust for the mouse driver int86(0x33, ®s, ®s); }//end of set_mouse_vertical_minmax //////////////////////////////////////////////////////////////////////////////// void set_mouse_ratio(int x_ratio, int y_ratio) { //for setting mouse movement ratio // - place value 15(equal to 15 Hex) in AX register. // - place x ratio value in CX register. // - place y ratio value in DX register. // - call the mouse interrupt. regs.x.ax = 0x0F; regs.x.cx = x_ratio; regs.x.dx = y_ratio; int86(0x33, ®s, ®s); }//end of set_mouse_ratio //////////////////////////////////////////////////////////////////////////////// void restrict_mouse(int xpmin, int ypmin, int xpmax, int ypmax) { //for restricting mouse movement to a particular screen area // - this function used the above specified functions. set_mouse_horizontal_minmax( xpmin, xpmax); set_mouse_vertical_minmax( ypmin, ypmax); }//end of restrict_mouse ///////////////////////////////////////////////////////////////////////////////// void free_mouse_in_text_mode(void) { //set free the mouse so that it can //move on whole screen. // - this function used the above specified functions. set_mouse_horizontal_minmax( 1, 80); set_mouse_vertical_minmax( 1, 24); }//end of free_mouse_in_text_mode //////////////////////////////////////////////////////////////////////////////