Tiny kprintf implementation, only decimal and hexadecimal output (unsigned).
[AROS.git] / test / keymaptest.c
blobf9a6398ea5bdf2d5aa655945d6a17afaca3c3c0d
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/keymap.h>
8 #include <proto/intuition.h>
9 #include <proto/dos.h>
10 #include <intuition/intuition.h>
11 #include <exec/libraries.h>
13 #include <stdio.h>
15 #define BUFSIZE 10
16 VOID HandleEvents(struct Window *win, UBYTE *buffer, LONG bufsize);
18 struct IntuitionBase *IntuitionBase;
19 struct Library *KeymapBase;
21 int main (int argc, char **argv)
23 UBYTE buffer[BUFSIZE];
25 KeymapBase = OpenLibrary("keymap.library", 37);
26 if (!KeymapBase)
27 printf("Failed to open keymap.library v37\n");
28 else
30 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
31 if (!IntuitionBase)
32 printf("Failed to open intuition.library v37\n");
33 else
35 struct Window *win;
37 win = OpenWindowTags(NULL,
38 WA_Width, 200,
39 WA_Height, 60,
40 WA_Title, (IPTR)"Maprawkey test (ESC to exit)",
41 WA_Flags, WFLG_ACTIVATE,
42 WA_IDCMP, IDCMP_RAWKEY,
43 TAG_DONE);
45 if (!win)
46 printf("Could not open window\n");
47 else
49 HandleEvents(win, buffer, BUFSIZE);
51 CloseWindow(win);
53 CloseLibrary((struct Library *)IntuitionBase);
55 CloseLibrary(KeymapBase);
57 return (0);
60 /*******************
61 ** HandleEvents **
62 *******************/
63 VOID HandleEvents(struct Window *win, UBYTE *buffer, LONG bufsize)
65 struct IntuiMessage *imsg;
66 struct MsgPort *port = win->UserPort;
67 BOOL terminated = FALSE;
68 WORD written;
69 struct InputEvent ie ={0,};
71 ie.ie_Class = IECLASS_RAWKEY;
73 while (!terminated)
75 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
78 switch (imsg->Class)
81 case IDCMP_REFRESHWINDOW:
82 BeginRefresh(win);
83 EndRefresh(win, TRUE);
84 break;
86 case IDCMP_RAWKEY:
87 ie.ie_Code = imsg->Code;
88 ie.ie_Qualifier = imsg->Qualifier;
89 printf("rawkey: code=$%04x, qual=$%04x\n",
90 ie.ie_Code, ie.ie_Qualifier);
92 ie.ie_EventAddress = imsg->IAddress;
94 written = MapRawKey(&ie, buffer, bufsize, NULL);
95 if (written == -1)
96 printf("Buffer owerflow !!\n");
97 else if (written)
99 printf("Map:");
100 Write(Output(), buffer, written);
101 printf("\n");
103 if (ie.ie_Code == 197)
104 terminated = TRUE;
105 break;
107 } /* switch (imsg->Class) */
108 ReplyMsg((struct Message *)imsg);
111 } /* if ((imsg = GetMsg(port)) != NULL) */
112 else
114 Wait(1L << port->mp_SigBit);
116 } /* while (!terminated) */
118 return;
119 } /* HandleEvents() */