home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / keyboard / keyinput.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  3.3 KB  |  91 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals.
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. /*
  23.  * Keyboard device matrix example...
  24.  */
  25.  
  26. #include <exec/types.h>
  27. #include <exec/io.h>
  28. #include <exec/ports.h>
  29. #include <exec/memory.h>
  30. #include <devices/inputevent.h>
  31. #include <devices/keyboard.h>
  32.  
  33. #include <proto/exec.h>
  34.  
  35. #include <stdio.h>
  36.  
  37. int CXBRK(VOID) { return(0); }
  38.  
  39. VOID Display_Event(struct InputEvent *keyEvent)
  40. {
  41.     printf("Got key event: KeyCode: %2x  Quailifiers: %4x\n",
  42.                keyEvent->ie_Code,
  43.                keyEvent->ie_Qualifier);
  44. }
  45.  
  46. VOID main(int argc, char *argv[])
  47. {
  48. struct IOStdReq   *keyRequest;
  49. struct MsgPort    *keyPort;
  50. struct InputEvent *keyEvent;
  51.        SHORT      loop;
  52.  
  53.     if (keyPort=CreatePort(NULL,NULL))
  54.     {
  55.         if (keyRequest=(struct IOStdReq *)CreateExtIO(keyPort,
  56.                                                   sizeof(struct IOStdReq)))
  57.         {
  58.             if (!OpenDevice("keyboard.device",NULL,
  59.                              (struct IORequest *)keyRequest,NULL))
  60.             {
  61.                 if (keyEvent=AllocMem(sizeof(struct InputEvent),MEMF_PUBLIC))
  62.                 {
  63.                     for (loop=0;loop<4;loop++)
  64.                     {
  65.                         keyRequest->io_Command=KBD_READEVENT;
  66.                         keyRequest->io_Data=(APTR)keyEvent;
  67.  
  68.                         /*
  69.                          * We want 1 event, so we just set the
  70.                          * length field to the size, in bytes
  71.                          * of the event.  For multiple events,
  72.                          * set this to a multiple of that size.
  73.                          * The keyboard device NEVER fills partial
  74.                          * events...
  75.                          */
  76.                         keyRequest->io_Length=sizeof(struct InputEvent);
  77.                         DoIO((struct IORequest *)keyRequest);
  78.  
  79.                             /* Check for CLI startup... */
  80.                         if (argc) Display_Event(keyEvent);
  81.                     }
  82.                     FreeMem(keyEvent,sizeof(struct InputEvent));
  83.                 }
  84.                 CloseDevice((struct IORequest *)keyRequest);
  85.             }
  86.             DeleteExtIO((struct IORequest *)keyRequest);
  87.         }
  88.         DeletePort(keyPort);
  89.     }
  90. }
  91.