Removed unnecessary calls to WaitForChar().
[AROS.git] / test / printnativekeytable.c
blobc755861a47b2641c01ce0d031441fe1764ad9622
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/intuition.h>
8 #include <proto/keymap.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <exec/execbase.h>
13 #include <devices/rawkeycodes.h>
14 #include <devices/inputevent.h>
16 #define NUM_STDKEYS 89
17 #define NOKEY -1
19 struct Library *KeymapBase;
21 static WORD std_keytable[NUM_STDKEYS] =
23 NOKEY , /* 000 (0x00) */
24 RAWKEY_ESCAPE , /* 001 (0x01) K_Escape */
25 RAWKEY_1 , /* 002 (0x02) K_1 */
26 RAWKEY_2 , /* 003 (0x03) K_2 */
27 RAWKEY_3 , /* 004 (0x04) K_3 */
28 RAWKEY_4 , /* 005 (0x05) K_4 */
29 RAWKEY_5 , /* 006 (0x06) K_5 */
30 RAWKEY_6 , /* 007 (0x07) K_6 */
31 RAWKEY_7 , /* 008 (0x08) K_7 */
32 RAWKEY_8 , /* 009 (0x09) K_8 */
33 RAWKEY_9 , /* 010 (0x0A) K_9 */
34 RAWKEY_0 , /* 011 (0x0B) K_0 */
35 RAWKEY_MINUS , /* 012 (0x0C) K_Minus */
36 RAWKEY_EQUAL , /* 013 (0x0D) K_Equal */
37 RAWKEY_BACKSPACE , /* 014 (0x0E) K_Backspace */
38 RAWKEY_TAB , /* 015 (0x0F) K_Tab */
39 RAWKEY_Q , /* 016 (0x10) K_Q */
40 RAWKEY_W , /* 017 (0x11) K_W */
41 RAWKEY_E , /* 018 (0x12) K_E */
42 RAWKEY_R , /* 019 (0x13) K_R */
43 RAWKEY_T , /* 020 (0x14) K_T */
44 RAWKEY_Y , /* 021 (0x15) K_Y */
45 RAWKEY_U , /* 022 (0x16) K_U */
46 RAWKEY_I , /* 023 (0x17) K_I */
47 RAWKEY_O , /* 024 (0x18) K_O */
48 RAWKEY_P , /* 025 (0x19) K_P */
49 RAWKEY_LBRACKET , /* 026 (0x1A) K_LBracket */
50 RAWKEY_RBRACKET , /* 027 (0x1B) K_RBracket */
51 RAWKEY_RETURN , /* 028 (0x1C) K_Enter */
52 RAWKEY_LCONTROL , /* 029 (0x1D) K_LCtrl */
53 RAWKEY_A , /* 030 (0x1E) K_A */
54 RAWKEY_S , /* 031 (0x1F) K_S */
55 RAWKEY_D , /* 032 (0x20) K_D */
56 RAWKEY_F , /* 033 (0x21) K_F */
57 RAWKEY_G , /* 034 (0x22) K_G */
58 RAWKEY_H , /* 035 (0x23) K_H */
59 RAWKEY_J , /* 036 (0x24) K_J */
60 RAWKEY_K , /* 037 (0x25) K_K */
61 RAWKEY_L , /* 038 (0x26) K_L */
62 RAWKEY_SEMICOLON , /* 039 (0x27) K_Semicolon */
63 RAWKEY_QUOTE , /* 040 (0x28) K_Quote */
64 RAWKEY_TILDE , /* 041 (0x29) K_BackQuote */
65 RAWKEY_LSHIFT , /* 042 (0x2A) K_LShift */
66 RAWKEY_2B , /* 043 (0x2B) K_BackSlash */
67 RAWKEY_Z , /* 044 (0x2C) K_Z */
68 RAWKEY_X , /* 045 (0x2D) K_X */
69 RAWKEY_C , /* 046 (0x2E) K_C */
70 RAWKEY_V , /* 047 (0x2F) K_V */
71 RAWKEY_B , /* 048 (0x30) K_B */
72 RAWKEY_N , /* 049 (0x31) K_N */
73 RAWKEY_M , /* 050 (0x32) K_M */
74 RAWKEY_COMMA , /* 051 (0x33) K_Comma */
75 RAWKEY_PERIOD , /* 052 (0x34) K_Period */
76 RAWKEY_SLASH , /* 053 (0x35) K_Slash */
77 RAWKEY_RSHIFT , /* 054 (0x36) K_RShift */
78 0x5c , /* 055 (0x37) K_KP_Multiply */
79 RAWKEY_LALT , /* 056 (0x38) K_LAlt */
80 RAWKEY_SPACE , /* 057 (0x39) K_Space */
81 RAWKEY_CAPSLOCK , /* 058 (0x3A) K_CapsLock */
82 RAWKEY_F1 , /* 059 (0x3B) K_F1 */
83 RAWKEY_F2 , /* 060 (0x3C) K_F2 */
84 RAWKEY_F3 , /* 061 (0x3D) K_F3 */
85 RAWKEY_F4 , /* 062 (0x3E) K_F4 */
86 RAWKEY_F5 , /* 063 (0x3F) K_F5 */
87 RAWKEY_F6 , /* 064 (0x40) K_F6 */
88 RAWKEY_F7 , /* 065 (0x41) K_F7 */
89 RAWKEY_F8 , /* 066 (0x42) K_F8 */
90 RAWKEY_F9 , /* 067 (0x43) K_F9 */
91 RAWKEY_F10 , /* 068 (0x44) K_F10 */
92 0x5A , /* 069 (0x45) K_NumLock */
93 NOKEY , /* 070 (0x46) K_Scroll_Lock ???? */
94 RAWKEY_KP_7 , /* 071 (0x47) K_KP_7 */
95 RAWKEY_KP_8 , /* 072 (0x48) K_KP_8 */
96 RAWKEY_KP_9 , /* 073 (0x49) K_KP_9 */
97 0x5D , /* 074 (0x4A) K_KP_Sub */
98 RAWKEY_KP_4 , /* 075 (0x4B) K_KP_4 */
99 RAWKEY_KP_5 , /* 076 (0x4C) K_KP_5 */
100 RAWKEY_KP_6 , /* 077 (0x4D) K_KP_6 */
101 0x5E , /* 078 (0x4E) K_KP_Add */
102 RAWKEY_KP_1 , /* 079 (0x4F) K_KP_1 */
103 RAWKEY_KP_2 , /* 080 (0x50) K_KP_2 */
104 RAWKEY_KP_3 , /* 081 (0x51) K_KP_3 */
105 RAWKEY_KP_0 , /* 082 (0x52) K_KP_0 */
106 RAWKEY_KP_DECIMAL , /* 083 (0x53) K_KP_Decimal */
107 NOKEY , /* 084 (0x54) */
108 NOKEY , /* 085 (0x55) */
109 RAWKEY_LESSGREATER , /* 086 (0x56) K_LessGreater */
110 RAWKEY_LAMIGA , /* 087 (0x57) K_F11 - Note: we map to LAMIGA, F11 rawkey code would be 0x4B */
111 RAWKEY_RAMIGA /* 088 (0x58) K_F12 - Note: we map to RAMIGA, F12 rawkey code would be 0x6F */
115 static void dotest(void)
117 struct Window *win;
118 struct IntuiMessage *msg;
119 BOOL quitme = FALSE;
121 KeymapBase = OpenLibrary("keymap.library", 0);
122 if (!KeymapBase) return;
124 win = OpenWindowTags(NULL, WA_Left, 20,
125 WA_Top, 20,
126 WA_Width, 300,
127 WA_Height, 20,
128 WA_Activate, TRUE,
129 WA_CloseGadget, TRUE,
130 WA_DepthGadget, TRUE,
131 WA_Title, (IPTR)"IDCMP_RAWKEY Test",
132 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_RAWKEY,
133 TAG_DONE);
134 if (!win)
136 CloseLibrary(KeymapBase);
137 return;
140 while(!quitme)
142 WaitPort(win->UserPort);
143 while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
145 switch(msg->Class)
147 case IDCMP_CLOSEWINDOW:
148 quitme = TRUE;
149 break;
151 case IDCMP_RAWKEY:
152 printf("RAWKEY %s: %3d (0x%02x) QUAL=0x%04x DEAD=0x%08lx ",
153 (msg->Code & IECODE_UP_PREFIX) ? "UP " : "DOWN",
154 (msg->Code & ~IECODE_UP_PREFIX),
155 (msg->Code & ~IECODE_UP_PREFIX),
156 msg->Qualifier,
157 (long)*(ULONG *)msg->IAddress);
160 struct InputEvent ie;
161 char buf[20];
162 WORD ret;
164 ie.ie_Class = IECLASS_RAWKEY;
165 ie.ie_Code = msg->Code;
166 ie.ie_Qualifier = msg->Qualifier;
167 ie.ie_EventAddress = *((ULONG **) msg->IAddress);
169 ret = MapRawKey(&ie, buf, sizeof(buf), NULL);
170 if (ret >= 0) buf[ret] = 0;
172 printf("MAPPED=%3d (%s)\n", ret, (ret == -1) ? "<NONE>" : ((ret == 0) ? "<ZERO>" : buf));
174 break;
176 ReplyMsg((struct Message *)msg);
180 CloseWindow(win);
181 CloseLibrary(KeymapBase);
184 int main(int argc, char **argv)
186 WORD *table;
187 WORD startindex = 0;
188 WORD endindex = 88;
189 WORD index;
190 WORD trashed = 0;
192 if (argc == 2)
194 if (strcmp(argv[1], "test") == 0)
196 dotest();
197 return 0;
200 index = strtol(argv[1], 0, 0);
202 if (index < 0) index = 0;
203 if (index > 88) index = 88;
205 startindex = endindex = index;
208 #if AROS_SIZEOFULONG == AROS_SIZEOFPTR
209 table = (WORD *)SysBase->ex_Reserved2[1]; /* set up in config/i386-native/Drivers/keyboard/kbdclass.c */
210 #else
211 table = NULL;
212 #endif
213 if (!table)
215 puts("Error: table points to NULL!\n");
216 return 0;
219 printf("Table address = 0x%p\n\n", table);
221 for(index = startindex; index <= endindex; index++)
223 printf("#%02d: %d (0x%x)\n", index, table[index], table[index]);
224 if (table[index] != std_keytable[index]) trashed++;
227 if (trashed)
229 printf("\n=============== Found %d trashed entries ============\n", trashed);
230 for(index = startindex; index <= endindex; index++)
232 if (table[index] != std_keytable[index])
234 printf("#%02d: %d (0x%x) should be: %d (0x%x)\n", index, table[index], table[index], std_keytable[index], std_keytable[index]);
239 return 0;