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_shared / test3.c < prev    next >
C/C++ Source or Header  |  1991-01-05  |  3KB  |  151 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.    long  status;
  55.    int   i;
  56.  
  57.    for (i=0; i<300; i++) {
  58.       mouse_event(i,0);
  59.    }
  60.    if ((status = DTInputStop(Unit0)) != 0) {
  61.       fprintf(stderr,"Error stopping unit 0 = %ld,%ld.\n",
  62.                status,Unit0->in_error);
  63.       fflush(stderr);
  64.       DTInputStart(Unit0);
  65.       DTInputFree(Unit0);
  66.       exit(0);
  67.    }
  68.    printf("Stopped - Try moving the mouse\n");
  69.    fflush(stdout);
  70.    Delay(5L*60L);
  71.    if ((status = DTInputStart(Unit0)) != 0) {
  72.       fprintf(stderr,"Error starting unit 0 = %ld,%ld.\n",
  73.                status,Unit0->in_error);
  74.       fflush(stderr);
  75.       DTInputFree(Unit0);
  76.       exit(0);
  77.    }
  78.    printf("Started\n");
  79.    fflush(stdout);
  80.    for (i=0; i<300; i++) {
  81.       mouse_event(300,i);
  82.    }
  83.    for (i=300; i>=0; i--) {
  84.       mouse_event(i,300);
  85.    }
  86.    if ((status = DTInputStop(Unit0)) != 0) {
  87.       fprintf(stderr,"Error stopping unit 0 = %ld,%ld.\n",
  88.                status,Unit0->in_error);
  89.       fflush(stderr);
  90.       DTInputStart(Unit0);
  91.       DTInputFree(Unit0);
  92.       exit(0);
  93.    }
  94.    printf("Stopped - Try moving the mouse\n");
  95.    fflush(stdout);
  96.    Delay(5L*60L);
  97.    if ((status = DTInputFlush(Unit0)) != 0) {
  98.       fprintf(stderr,"Error flusing unit 0 = %ld,%ld.\n",
  99.                status,Unit0->in_error);
  100.       fflush(stderr);
  101.       DTInputStart(Unit0);
  102.       DTInputFree(Unit0);
  103.       exit(0);
  104.    }
  105.    printf("Flushed\n");
  106.    fflush(stdout);
  107.    if ((status = DTInputStart(Unit0)) != 0) {
  108.       fprintf(stderr,"Error starting unit 0 = %ld,%ld.\n",
  109.                status,Unit0->in_error);
  110.       fflush(stderr);
  111.       DTInputFree(Unit0);
  112.       exit(0);
  113.    }
  114.    printf("Started\n");
  115.    fflush(stdout);
  116.    for (i=300; i>=0; i--) {
  117.       mouse_event(0,i);
  118.    }
  119.  
  120.    return (0);
  121. }
  122.  
  123. mouse_event(x,y)
  124. int   x;
  125. int   y;
  126. {
  127.    long  status;
  128.  
  129.    event.ie_NextEvent = NULL;
  130.    event.ie_Class = IECLASS_POINTERPOS;
  131.    event.ie_SubClass = 0;
  132.    event.ie_Code = 0;
  133.    event.ie_Qualifier = 0;
  134.    event.ie_position.ie_xy.ie_x = x;
  135.    event.ie_position.ie_xy.ie_y = y;
  136.    event.ie_TimeStamp.tv_secs = 0;
  137.    event.ie_TimeStamp.tv_micro = 0;
  138.  
  139.    if ((status = DTInputWriteEvent(Unit0,(BYTE *) &event,
  140.          sizeof(event))) != 0) {
  141.       fprintf(stderr,"Error writing event to unit 0 = %ld,%ld.\n",
  142.                status,Unit0->in_error);
  143.       fflush(stderr);
  144.       DTInputDestroy(Unit0);
  145.       exit(0);
  146.    }
  147.  
  148.    return (0);
  149. }
  150.  
  151.