home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_srgp.lha / srgp / examples / test_keyboard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-09  |  1.8 KB  |  92 lines

  1. /**
  2. This program places the keyboard in RAW EVENT mode.
  3. **/
  4.  
  5.  
  6. #include "srgp.h"
  7.  
  8. #ifdef THINK_C
  9. void exit(int);
  10. #endif
  11.  
  12. static deluxe_locator_measure dlm;
  13. static char buffer[100];
  14. static char kmstring[2];
  15. static deluxe_keyboard_measure dkm;
  16.  
  17. static int lineheight, textw, texta, textd;
  18.  
  19. static int timeout;
  20.  
  21. static int locatorMode = SAMPLE;
  22. static char *modeNames[] = {"INACTIVE", "SAMPLE", "EVENT"};
  23.  
  24. static int locatorButtonMask = LEFT_BUTTON_MASK;
  25.  
  26.  
  27. static void DisplayPrompt (void)
  28. {
  29.    int y = 100;
  30.    
  31.    y -= lineheight;
  32.    SRGP_text (SRGP_defPoint(10,y), "Hit any keyboard key ('q' to exit)");
  33. }   
  34.  
  35. static void DisplayKeyboardMeasure (void)
  36. {
  37.    int y = 100;
  38.  
  39.    SRGP_setColor (COLOR_WHITE);
  40.    SRGP_fillRectangleCoord (0,0, 400, 400);
  41.    
  42.    SRGP_setColor (COLOR_BLACK);
  43.    
  44.    y -= lineheight;
  45.    sprintf (buffer, "Value: %c (hex %4x)", dkm.buffer[0], dkm.buffer[0]);
  46.    SRGP_text (SRGP_defPoint(10,y), buffer);
  47.    
  48.    y -= lineheight;
  49.    sprintf (buffer, "Modifier chord: %d, %d, %d", 
  50.         dkm.modifier_chord[0], dkm.modifier_chord[1], 
  51.         dkm.modifier_chord[2]);
  52.    SRGP_text (SRGP_defPoint(10,y), buffer);
  53.  
  54.    y -= lineheight;
  55.    sprintf (buffer, "Timestamp: %8d seconds, %2d ticks", 
  56.         dkm.timestamp.seconds, dkm.timestamp.ticks);
  57.    SRGP_text (SRGP_defPoint(10,y), buffer);
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. main()
  65. {
  66.    SRGP_begin ("Keyboard exercise", 400, 100, 1, FALSE);
  67.  
  68.    SRGP_setInputMode (KEYBOARD, EVENT);
  69.    SRGP_setKeyboardProcessingMode (RAW);
  70.  
  71.    dkm.buffer = kmstring;
  72.    dkm.buffer_length = 2;
  73.  
  74.    SRGP_inquireTextExtent ("High", &textw, &texta, &textd);
  75.    lineheight = texta + textd;
  76.    
  77.    DisplayPrompt();
  78.  
  79.    
  80.    while (1) {
  81.       switch (SRGP_waitEvent (INDEFINITE)) {
  82.        case KEYBOARD:
  83.      SRGP_getDeluxeKeyboard (&dkm);
  84.      DisplayKeyboardMeasure();
  85.      if (dkm.buffer[0] == 'q') {
  86.         SRGP_end();
  87.         exit(0);
  88.      }
  89.       }
  90.    }
  91. }
  92.