tools/createdtdesc: provide HOST_LDFLAGS when linking
[AROS.git] / test / keymaptest.c
blobbb6b6588394fb5c98ca549f473c23f2829559ccb
1 #include <proto/exec.h>
2 #include <proto/keymap.h>
3 #include <proto/intuition.h>
4 #include <proto/dos.h>
5 #include <intuition/intuition.h>
6 #include <exec/libraries.h>
8 #include <stdio.h>
10 #define BUFSIZE 10
11 VOID HandleEvents(struct Window *win, UBYTE *buffer, LONG bufsize);
13 struct IntuitionBase *IntuitionBase;
14 struct Library *KeymapBase;
16 int main (int argc, char **argv)
18 UBYTE buffer[BUFSIZE];
20 KeymapBase = OpenLibrary("keymap.library", 37);
21 if (!KeymapBase)
22 printf("Failed to open keymap.library v37\n");
23 else
25 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
26 if (!IntuitionBase)
27 printf("Failed to open intuition.library v37\n");
28 else
30 struct Window *win;
32 win = OpenWindowTags(NULL,
33 WA_Width, 200,
34 WA_Height, 60,
35 WA_Title, (IPTR)"Maprawkey test (ESC to exit)",
36 WA_Flags, WFLG_ACTIVATE,
37 WA_IDCMP, IDCMP_RAWKEY,
38 TAG_DONE);
40 if (!win)
41 printf("Could not open window\n");
42 else
44 HandleEvents(win, buffer, BUFSIZE);
46 CloseWindow(win);
48 CloseLibrary((struct Library *)IntuitionBase);
50 CloseLibrary(KeymapBase);
52 return (0);
55 /*******************
56 ** HandleEvents **
57 *******************/
58 VOID HandleEvents(struct Window *win, UBYTE *buffer, LONG bufsize)
60 struct IntuiMessage *imsg;
61 struct MsgPort *port = win->UserPort;
62 BOOL terminated = FALSE;
63 WORD written;
64 struct InputEvent ie ={0,};
66 ie.ie_Class = IECLASS_RAWKEY;
68 while (!terminated)
70 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
73 switch (imsg->Class)
76 case IDCMP_REFRESHWINDOW:
77 BeginRefresh(win);
78 EndRefresh(win, TRUE);
79 break;
81 case IDCMP_RAWKEY:
82 ie.ie_Code = imsg->Code;
83 ie.ie_Qualifier = imsg->Qualifier;
84 printf("rawkey: code=$%04x, qual=$%04x\n",
85 ie.ie_Code, ie.ie_Qualifier);
87 ie.ie_EventAddress = imsg->IAddress;
89 written = MapRawKey(&ie, buffer, bufsize, NULL);
90 if (written == -1)
91 printf("Buffer owerflow !!\n");
92 else if (written)
94 printf("Map:");
95 Write(Output(), buffer, written);
96 printf("\n");
98 if (ie.ie_Code == 197)
99 terminated = TRUE;
100 break;
102 } /* switch (imsg->Class) */
103 ReplyMsg((struct Message *)imsg);
106 } /* if ((imsg = GetMsg(port)) != NULL) */
107 else
109 Wait(1L << port->mp_SigBit);
111 } /* while (!terminated) */
113 return;
114 } /* HandleEvents() */