home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / imc9102.zip / MOUSE2.C < prev    next >
C/C++ Source or Header  |  1991-01-07  |  3KB  |  103 lines

  1. #include <dos.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <graph.h>
  6.  
  7. void main(void)
  8.    {
  9.    union REGS in_regs, out_regs;
  10.    int row, col;
  11.    int number_pressed, number_released;
  12.  
  13.    /* Clear the screen */
  14.    _clearscreen(_GCLEARSCREEN);
  15.  
  16.    /* Initialize the mouse cursor */
  17.    in_regs.x.ax = 0;
  18.    int86(0x33, &in_regs, &out_regs);
  19.    if (!out_regs.x.ax)
  20.       {
  21.       printf("Mouse could not be "
  22.              "initialized.\n");
  23.       exit(1);
  24.       }
  25.    printf("Mouse initialized.\n");
  26.  
  27.    /* Show the mouse cursor */
  28.    in_regs.x.ax = 1;
  29.    int86(0x33, &in_regs, &out_regs);
  30.  
  31.    /* Prompt user to move the cursor */
  32.    row = 1;
  33.    col = 1;
  34.    printf("Press any key to move the "
  35.           "mouse cursor to (1, 1).\n");
  36.    getch();
  37.  
  38.    /* Move the mouse cursor */
  39.    in_regs.x.dx = 8 * (row - 1);
  40.    in_regs.x.cx = 8 * (col - 1);
  41.    in_regs.x.ax = 4;
  42.    int86(0x33, &in_regs, &out_regs);
  43.  
  44.    /* Clear the left button queue */
  45.    in_regs.x.bx = 0;
  46.    in_regs.x.ax = 5;
  47.    int86(0x33, &in_regs, &out_regs);
  48.  
  49.    /* Tell user to press left button */
  50.    printf("Press the left mouse button a number of ");
  51.    printf("times, then any key.\n");
  52.    getch();
  53.  
  54.    /* Read the left button queue */
  55.    in_regs.x.bx = 0;
  56.    in_regs.x.ax = 5;
  57.    int86(0x33, &in_regs, &out_regs);
  58.  
  59.    /* Convert to text coordinates */
  60.    row = out_regs.x.dx / 8 + 1;
  61.    col = out_regs.x.cx / 8 + 1;
  62.  
  63.    /* Print the queue information */
  64.    number_pressed = out_regs.x.bx;
  65.    printf("You pressed it %d times.\n",
  66.           number_pressed);
  67.    printf("Last time at (%d, %d).\n",
  68.           row, col);
  69.  
  70.    /* Clear the left release queue */
  71.    in_regs.x.bx = 0;
  72.    in_regs.x.ax = 6;
  73.    int86(0x33, &in_regs, &out_regs);
  74.  
  75.    /* Prompt the user */
  76.    printf("Press the left mouse button "
  77.           "a few times, and then press "
  78.           "any key.\n");
  79.    getch();
  80.  
  81.    /* Read the release queue */
  82.    in_regs.x.bx = 0;
  83.    in_regs.x.ax = 6;
  84.    int86(0x33, &in_regs, &out_regs);
  85.  
  86.    /* Convert to text position */
  87.    row = out_regs.x.dx / 8 + 1;
  88.    col = out_regs.x.cx / 8 + 1;
  89.  
  90.    /* Print the release queue info */
  91.    number_released = out_regs.x.bx;
  92.    printf("You released it %d times.\n",
  93.            number_released);
  94.    printf("Last time at (%d, %d).\n",
  95.            row, col);
  96.  
  97.    /* END OF MOUSE2.C */
  98.    puts("Press any key to exit");
  99.    getch();
  100.    in_regs.x.ax = 2;
  101.    int86(0x33, &in_regs, &out_regs);
  102.    }
  103.