home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_03 / 1n03080a < prev    next >
Text File  |  1990-07-10  |  3KB  |  94 lines

  1.  
  2. #include        <conio.h>
  3.  
  4. /*
  5. *************************************************************
  6. *       InputNoWait - waits for key or mouse button press,
  7. *               then returns value
  8. *
  9. *       Parameters:
  10. *               x (out) - x position of mouse when button
  11. *                       pressed
  12. *               y (out) - y position of mouse when button
  13. *                       pressed
  14. *
  15. *       Returns:
  16. *               For mouse, returns MOUSE_L or MOUSE_R (left
  17. *                       or right button).
  18. *               For mouse button release, returns MOUSE_OFF.
  19. *               For normal key press, returns key code
  20. *                       (extended ascii).
  21. *               For extended key press, returns second byte
  22. *                       of extended key code * -1.
  23. *               Unlike input, this routine does not wait
  24. *               for mouse button release prior to returning.
  25. *
  26. *       Notes:
  27. *               This routine blocks waiting user action.
  28. *               Mouse coordinates are virtual screen
  29. *               coordinates.
  30. *               Unlike input, this routine does not wait for
  31. *               mouse button release prior to returning.
  32. *
  33. *       Copyright:
  34. *               Original code by William H. Roetzheim
  35. *************************************************************
  36. */
  37.  
  38. #define INVALID         -1
  39. #define MOUSE_L         -2
  40. #define MOUSE_R         -3
  41. #define MOUSE_OFF       -4
  42.  
  43. int     InputNoWait (int *x, int *y)
  44. {
  45.         int     m1, m2, m3, m4;
  46.         int     mouse;
  47.         int     ch;
  48.         int     retval = 0;
  49.         static  int     mouse_press = FALSE;
  50.  
  51.         MouseOn ();
  52.  
  53.         *x = INVALID;
  54.         *y = INVALID;
  55.         while (retval == 0)
  56.         {
  57.                 /* return mouse if pressed */
  58.                 m1 = 3;         /* check button press on mouse */
  59.                 m2 = 0;
  60.                 IntMouse (&m1, &m2, &m3, &m4);
  61.                 if (m2 != 0)
  62.                 {
  63.                         mouse = m2;
  64.                         *x = m3;
  65.                         *y = m4;
  66.                         if (mouse == 1)
  67.                         {
  68.                                 retval = MOUSE_L;
  69.                                 mouse_press = TRUE;
  70.                         }
  71.                         else retval = MOUSE_R;
  72.                 }
  73.                 else if (mouse_press == TRUE)   /* just released button */
  74.                 {
  75.                         retval = MOUSE_UP;
  76.                         mouse_press = FALSE;
  77.                         m1 = 6;
  78.                         m2 = 0;
  79.                         IntMouse (&m1, &m2, &m3, &m4);
  80.                         *x = m3;
  81.                         *y = m4;
  82.                 }
  83.                 if (kbhit() != 0)
  84.                 {
  85.                    ch = getch();
  86.                    /* get extended key code */
  87.                    if (ch == 0) ch = -(getch());       
  88.                    retval = ch;
  89.                 }
  90.         }
  91.         MouseOff ();
  92.         return retval;
  93. }
  94.