home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 499.lha / InputDeviceToolKit / input.lzh / src / DeviceToolKits / Input / test / test2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-05  |  1.9 KB  |  106 lines

  1. #include <stdio.h>
  2.  
  3. #include "DeviceToolKits/Input.h"
  4. #ifndef  TESTPROTO
  5. #define  NO_PRAGMAS  1
  6. #endif
  7. #include "DeviceToolKits/proto/Input.h"
  8. #include "DeviceToolKits/InputBase.h"
  9.  
  10. DTInput_t            Unit0;
  11. struct   InputEvent  event;
  12.  
  13. main(argc,argv)
  14. int   argc;
  15. char  *argv[];
  16. {
  17.    long  status;
  18.    int   i;
  19.  
  20. #ifdef   TESTSHARED
  21. /*  Open the Input library  */
  22.  
  23.    DTInputOpen(DTINPUTREV);
  24. #endif
  25.  
  26. /*  Try to initialize unit 0 of the Input  */
  27.  
  28.    if ((Unit0 = DTInputCreate(&status)) == NULL) {
  29.       fprintf(stderr,"Error initializing unit 0 = %ld.\n",status);
  30.       fflush(stderr);
  31.       goto cleanup;
  32.    }
  33.  
  34.    fprintf(stderr,"Unit0 = %lX\n",(long) Unit0);
  35.    fflush(stderr);
  36.  
  37. /*  Do some fun stuff with the mouse  */
  38.  
  39.    for (i=0; i<1; i++) {
  40.       do_box();
  41.    }
  42.  
  43. /*  Free the stuff  */
  44.  
  45. cleanup:
  46.    DTInputFree(Unit0);
  47. #ifdef   TESTSHARED
  48.    DTInputClose();
  49. #endif
  50. }
  51.  
  52. do_box()
  53. {
  54.    int   i;
  55.  
  56.    for (i=0; i<300; i++) {
  57.       mouse_event(i,0);
  58.    }
  59.    printf("Try moving the mouse\n");
  60.    fflush(stdout);
  61.    Delay(5L*60L);
  62.    for (i=0; i<300; i++) {
  63.       mouse_event(300,i);
  64.    }
  65.    for (i=300; i>=0; i--) {
  66.       mouse_event(i,300);
  67.    }
  68.    printf("Try moving the mouse\n");
  69.    fflush(stdout);
  70.    Delay(5L*60L);
  71.    for (i=300; i>=0; i--) {
  72.       mouse_event(0,i);
  73.    }
  74.  
  75.    return (0);
  76. }
  77.  
  78. mouse_event(x,y)
  79. int   x;
  80. int   y;
  81. {
  82.    long  status;
  83.  
  84.    event.ie_NextEvent = NULL;
  85.    event.ie_Class = IECLASS_POINTERPOS;
  86.    event.ie_SubClass = 0;
  87.    event.ie_Code = 0;
  88.    event.ie_Qualifier = 0;
  89.    event.ie_position.ie_xy.ie_x = x;
  90.    event.ie_position.ie_xy.ie_y = y;
  91.    event.ie_TimeStamp.tv_secs = 0;
  92.    event.ie_TimeStamp.tv_micro = 0;
  93.  
  94.    if ((status = DTInputWriteEvent(Unit0,(BYTE *) &event,
  95.          sizeof(event))) != 0) {
  96.       fprintf(stderr,"Error writing event to unit 0 = %ld,%ld.\n",
  97.                status,Unit0->in_error);
  98.       fflush(stderr);
  99.       DTInputFree(Unit0);
  100.       exit(0);
  101.    }
  102.  
  103.    return (0);
  104. }
  105.  
  106.