home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / mouse / tcmouse / mtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-15  |  2.4 KB  |  83 lines

  1. /****************** #pragma inline  ******************************/
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #include <conio.h>
  5.  
  6. #include "mouse.h"
  7.  
  8.  
  9. void near clear(void);
  10. /* clears the screen */
  11.  
  12. void near gotoyx(int y, int x);
  13. /* position the cursor */
  14.  
  15.  
  16.  
  17.  
  18.  
  19. main()
  20. {
  21.   char c;
  22.   int button,xpos,ypos;
  23.   int status,count;
  24.  
  25.   if ( ! mouse_init()){
  26.       printf("\nMOUSE NOT INSTALLED!!\n");
  27.       exit(1);
  28.       }
  29.   clear();
  30.   gotoyx(0,0);
  31.   printf("Move the mouse and press the buttons,\n");
  32.   printf("then press any key to go on.\n");
  33.   settext(0,0xffff,0x7700);
  34.   pos_mouse(16,24);
  35.   show_cursor();
  36.   setspeed(15,15);/* set the ratio of mouse movement to cursor movement */
  37.   while (! kbhit()) {
  38.       get_status(&button,&xpos,&ypos); /* get status of buttons and position */
  39.       if (button>0) {
  40.           xpos/=8; /* the positions returned are in pixels, 8x8 per char */
  41.           ypos/=8;
  42.           hide_cursor();     /* hide cursor during screen update, otherwise */
  43.           gotoyx(ypos,xpos); /* when you move the mouse the screen goes back */
  44.           if (button == 1) {
  45.               putchar('\xAE');
  46.               gotoyx(23,0);
  47.               printf(" Left button pressed, at %3d,%3d",xpos,ypos);
  48.           }else if (button == 2) {
  49.               putchar('\xAF');
  50.               gotoyx(23,0);
  51.               printf("Right button pressed, at %3d,%3d",xpos,ypos);
  52.           }else{    /* then button == 3, both buttons were pressed */
  53.               putchar('\xD8');
  54.               gotoyx(23,0);
  55.               printf("Both buttons pressed, at %3d,%3d",xpos,ypos);
  56.               }
  57.           show_cursor();
  58.           }
  59.  
  60.   } /* end while */
  61.   getch(); /* get rid of the character that was pressed */
  62.   hide_cursor();
  63.   clear();
  64.   printf("This time let's limit the mouse to the center area of the screen\n");
  65.   printf("Notice the mouse cursor has new boundaries. press any key...\n");
  66.   pos_mouse(40*8,12*8);
  67.   setvbounds(9*8,20*8);
  68.   sethbounds(20*8,60*8);
  69.   show_cursor();
  70.   b_press(0,&status,&count,&xpos,&ypos);
  71.   while (! kbhit() ) {
  72.       get_status(&button,&xpos,&ypos);
  73.       gotoyx(ypos/8,xpos/8);
  74.       if (button >2){ /* if both buttons pressed */
  75.       hide_cursor();
  76.           puts("Both buttons pressed...");
  77.           show_cursor();
  78.           }
  79.       }
  80.   getch(); /* get rid of the character that was pressed */
  81.   hide_cursor();
  82. }
  83.