home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_02 / 1n02079a < prev    next >
Text File  |  1990-07-09  |  2KB  |  83 lines

  1.  
  2. /* inpause() waits for a keypress or a  mouse button press, then returns */
  3. /* the key if a keyboard entry was made, or <CR> if RIGHT mouse button was */
  4. /* pressed, ASCII 127 for any other button.  The value to return with a */
  5. /* mouse button press was a hard choice for me.  A '\0' is used for */
  6. /* function keys and alternate keys like the cursor keys as the first */
  7. /* of two arguments.  An '\n' is not normally returned by the keyboard, */
  8. /* because keyboards are by default opened as binary devices.  So <CR> */
  9. /* seemed the least objectionable value to use. 127 just seemed like a */
  10. /* safe no-op. */
  11.  
  12. int inpause()
  13. {
  14.     int c=127;  /* default for LEFT BUTTON or BOTH BUTTONS */
  15.     mstruc m;
  16.  
  17.     mouse_clear();
  18.     for(;;)
  19.     {
  20.         if(kbhit())
  21.         {
  22.             c=getch();
  23.             break;
  24.         }
  25.         m=button_read();
  26.         if(m.status)    /* any button press will force a return */
  27.         {
  28.             if(m.status==RIGHT_BUTTON)
  29.                 c=CARRIAGE_RETURN;
  30.             break;
  31.         }
  32.     }
  33.     return c;
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40. /* mouse_gets() is a substitute for gets(), in which RIGHT_BUTTON is able */
  41. /* to be detected as a carriage return.  Like gets(), the string that */
  42. /* is returned is null-terminated. */
  43.  
  44. char * mouse_gets(sptr)
  45. char *sptr;
  46. {
  47.     int i=0;
  48.     unsigned char c='\0';
  49.  
  50.     mouse_clear();
  51.     while(c != CARRIAGE_RETURN)
  52.     {
  53.         if(button_read().status==RIGHT_BUTTON)
  54.             c = CARRIAGE_RETURN;
  55.         if(kbhit())
  56.         {
  57.             c=getche();
  58.             if(c==BACKSPACE)
  59.             {
  60.                 putc(' ', stdout);
  61.                 putc(BACKSPACE,stdout);
  62.                 i--;
  63.                 if(i<0)
  64.                     i=0;
  65.                 sptr[i]='\0';
  66.             }
  67.             else
  68.             {
  69.                 if(c != CARRIAGE_RETURN)
  70.                 {
  71.                     sptr[i]=c;
  72.                     i++;
  73.                 }
  74.             }
  75.         }
  76.     }
  77.     sptr[i]='\0';
  78.     printf("\n");
  79.  
  80.     return sptr;
  81. }
  82.  
  83.