1 | /* $Id: $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * dumpchar - dump scancodes, virtual keys, and character conversions.
|
---|
5 | *
|
---|
6 | * Copyright (c) 2006 knut st. osmundsen <bird@anduin.net>
|
---|
7 | *
|
---|
8 | * GPL
|
---|
9 | *
|
---|
10 | */
|
---|
11 |
|
---|
12 | /*******************************************************************************
|
---|
13 | * Header Files *
|
---|
14 | *******************************************************************************/
|
---|
15 | #define INCL_PM
|
---|
16 | #define INCL_ERRORS
|
---|
17 | #define INCL_DOS
|
---|
18 | #include <os2.h>
|
---|
19 | #include <stdio.h>
|
---|
20 | #include <string.h>
|
---|
21 |
|
---|
22 |
|
---|
23 | /** The WinTranlateChar2 operation. */
|
---|
24 | typedef enum WINTCOP
|
---|
25 | {
|
---|
26 | TC_CHARTOSCANCODE = 0,
|
---|
27 | TC_SCANCODETOCHAR,
|
---|
28 | TC_VIRTUALKEYTOSCANCODE,
|
---|
29 | TC_SCANCODETOVIRTUALKEY,
|
---|
30 | TC_SCANTOOEMSCAN,
|
---|
31 | TC_OEMSCANTOSCAN,
|
---|
32 | TC_SIZE_HACK = 0x7fff
|
---|
33 | } WINTCOP;
|
---|
34 |
|
---|
35 | /** @name WinTranslateChar2 shift state.
|
---|
36 | * This state goes with scancode input/output.
|
---|
37 | * @{ */
|
---|
38 | #define TCF_LSHIFT 0x1
|
---|
39 | #define TCF_RSHIFT 0x2
|
---|
40 | #define TCF_SHIFT (TCF_LSHIFT | TCF_RSHIFT)
|
---|
41 | #define TCF_LCONTROL 0x4
|
---|
42 | #define TCF_RCONTROL 0x8
|
---|
43 | #define TCF_CONTROL (TCF_LCONTROL | TCF_RCONTROL)
|
---|
44 | #define TCF_ALT 0x10
|
---|
45 | #define TCF_ALTGR 0x20
|
---|
46 | #define TCF_CAPSLOCK 0x40
|
---|
47 | #define TCF_NUMLOCK 0x80
|
---|
48 | #define TCF_MAX_BITS 8 /**< bits 0-7 are real shift states */
|
---|
49 | #define TCF_OEMSCANCODE 0x100
|
---|
50 | #define TCF_EXTENDEDKEY 0x200
|
---|
51 | /** @} */
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Char to/from keyboard code translator.
|
---|
55 | *
|
---|
56 | * @returns A combination of some of the KC_* values.
|
---|
57 | * @param usCodePage The code page. Anything goes, apparently ignored.
|
---|
58 | * @param pusCharInOut Where to get the char/code to be translated and to
|
---|
59 | * put the output upon return.
|
---|
60 | * @param pulDeadKeyInfo Previous, dead key.
|
---|
61 | * @param enmOperation The kind of translation.
|
---|
62 | * @param pfShiftState Where to read/store the shift state. Used when
|
---|
63 | * translating from/to scancodes.
|
---|
64 | */
|
---|
65 | USHORT APIENTRY WinTranslateChar2(USHORT usCodePage,
|
---|
66 | PUSHORT pusCharInOut,
|
---|
67 | PULONG pulDeadKeyInfo,
|
---|
68 | WINTCOP enmOperation,
|
---|
69 | PUSHORT pfShiftState);
|
---|
70 |
|
---|
71 |
|
---|
72 | int main()
|
---|
73 | {
|
---|
74 | /*
|
---|
75 | * PM prolog.
|
---|
76 | */
|
---|
77 | PPIB pPib;
|
---|
78 | DosGetInfoBlocks(NULL, &pPib);
|
---|
79 | pPib->pib_ultype = 3;
|
---|
80 | HAB hab = WinInitialize(0);
|
---|
81 | HMQ hmq = WinCreateMsgQueue(hab, 0); (void)hmq;
|
---|
82 |
|
---|
83 | /*
|
---|
84 | * char to scancode to virtual key.
|
---|
85 | */
|
---|
86 | printf("char -> scancode -> virtual key\n");
|
---|
87 | for (unsigned iChar = 0; iChar < 256; iChar++) {
|
---|
88 | /* to scancode */
|
---|
89 | USHORT usScanCode = iChar;
|
---|
90 | ULONG ulScanCodeDeadKeyInfo = 0;
|
---|
91 | USHORT fScanCodeShiftState = 0;
|
---|
92 | USHORT fScanCodeRc = WinTranslateChar2(0, &usScanCode, &ulScanCodeDeadKeyInfo, TC_CHARTOSCANCODE, &fScanCodeShiftState);
|
---|
93 | if (usScanCode) {
|
---|
94 | /* to virtual key */
|
---|
95 | USHORT usVirtualKey = usScanCode;
|
---|
96 | ULONG ulVirtualKeyDeadKeyInfo = ulScanCodeDeadKeyInfo;
|
---|
97 | USHORT fVirtualKeyShiftState = fScanCodeShiftState;
|
---|
98 | USHORT fVirtualKeyRc = WinTranslateChar2(0, &usVirtualKey, &ulVirtualKeyDeadKeyInfo, TC_SCANCODETOVIRTUALKEY, &fVirtualKeyShiftState);
|
---|
99 | printf("%d/%#x: %04x %lx %04x %04x | %04x %lx %04x %04x\n",
|
---|
100 | iChar, iChar,
|
---|
101 | usScanCode, ulScanCodeDeadKeyInfo, fScanCodeShiftState, fScanCodeRc,
|
---|
102 | usVirtualKey, ulVirtualKeyDeadKeyInfo, fVirtualKeyShiftState, fVirtualKeyRc);
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | /*
|
---|
107 | * scancode to char and virtual key.
|
---|
108 | */
|
---|
109 | printf("\n"
|
---|
110 | "\n"
|
---|
111 | "\n"
|
---|
112 | "scancode -> char + virtual key \n");
|
---|
113 | for (unsigned iScanCode = 0; iScanCode < 256; iScanCode++) {
|
---|
114 | for (unsigned fShiftState = 0; fShiftState < (1 << TCF_MAX_BITS); fShiftState++) {
|
---|
115 | /* to char */
|
---|
116 | USHORT usChar = iScanCode;
|
---|
117 | ULONG ulCharDeadKeyInfo = 0;
|
---|
118 | USHORT fCharShiftState = fShiftState;
|
---|
119 | USHORT fCharRc = WinTranslateChar2(0, &usChar, &ulCharDeadKeyInfo, TC_SCANCODETOCHAR, &fCharShiftState);
|
---|
120 |
|
---|
121 | /* to virtual key */
|
---|
122 | USHORT usVirtualKey = iScanCode;
|
---|
123 | ULONG ulVirtualKeyDeadKeyInfo = 0;
|
---|
124 | USHORT fVirtualKeyShiftState = fShiftState;
|
---|
125 | USHORT fVirtualKeyRc = WinTranslateChar2(0, &usVirtualKey, &ulVirtualKeyDeadKeyInfo, TC_SCANCODETOVIRTUALKEY, &fVirtualKeyShiftState);
|
---|
126 | if (usChar && usVirtualKey) {
|
---|
127 | printf("%3d/%#04x+%02x: %04x %lx %04x %04x | %04x %lx %04x %04x\n",
|
---|
128 | iScanCode, iScanCode, fShiftState,
|
---|
129 | usChar, ulCharDeadKeyInfo, fCharShiftState, fCharRc,
|
---|
130 | usVirtualKey, ulVirtualKeyDeadKeyInfo, fVirtualKeyShiftState, fVirtualKeyRc);
|
---|
131 | } else if (usChar) {
|
---|
132 | printf("%3d/%#04x+%02x: %04x %lx %04x %04x\n",
|
---|
133 | iScanCode, iScanCode, fShiftState,
|
---|
134 | usChar, ulCharDeadKeyInfo, fCharShiftState, fCharRc);
|
---|
135 | } else if (usVirtualKey) {
|
---|
136 | printf("%3d/%#04x+%02x: | %04x %lx %04x %04x\n",
|
---|
137 | iScanCode, iScanCode, fShiftState,
|
---|
138 | usVirtualKey, ulVirtualKeyDeadKeyInfo, fVirtualKeyShiftState, fVirtualKeyRc);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | /*
|
---|
144 | * virtual key to scancode and char.
|
---|
145 | */
|
---|
146 | printf("\n"
|
---|
147 | "\n"
|
---|
148 | "\n"
|
---|
149 | "virtual key -> scancode + char\n");
|
---|
150 | for (unsigned iVirtualKey = 0; iVirtualKey < 512; iVirtualKey++) {
|
---|
151 | /* to scancode */
|
---|
152 | USHORT usScanCode = iVirtualKey;
|
---|
153 | ULONG ulScanCodeDeadKeyInfo = 0;
|
---|
154 | USHORT fScanCodeShiftState = 0;
|
---|
155 | USHORT fScanCodeRc = WinTranslateChar2(0, &usScanCode, &ulScanCodeDeadKeyInfo, TC_VIRTUALKEYTOSCANCODE, &fScanCodeShiftState);
|
---|
156 | if (usScanCode) {
|
---|
157 | /* to char */
|
---|
158 | USHORT usChar = iVirtualKey;
|
---|
159 | ULONG ulCharDeadKeyInfo = 0;
|
---|
160 | USHORT fCharShiftState = 0;
|
---|
161 | USHORT fCharRc = WinTranslateChar2(0, &usChar, &ulCharDeadKeyInfo, TC_SCANCODETOCHAR, &fCharShiftState);
|
---|
162 | if (usChar) {
|
---|
163 | printf("%3d/%#04x: %04x %lx %04x %04x | %04x %lx %04x %04x\n",
|
---|
164 | iVirtualKey, iVirtualKey,
|
---|
165 | usScanCode, ulScanCodeDeadKeyInfo, fScanCodeShiftState, fScanCodeRc,
|
---|
166 | usChar, ulCharDeadKeyInfo, fCharShiftState, fCharRc);
|
---|
167 | } else {
|
---|
168 | printf("%3d/%#04x: %04x %lx %04x %04x\n",
|
---|
169 | iVirtualKey, iVirtualKey,
|
---|
170 | usScanCode, ulScanCodeDeadKeyInfo, fScanCodeShiftState, fScanCodeRc);
|
---|
171 | }
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | printf("\n"
|
---|
176 | "\n"
|
---|
177 | "\n"
|
---|
178 | "scan code -> oem scan code\n");
|
---|
179 | for (unsigned iScanCode = 0; iScanCode < 256; iScanCode++) {
|
---|
180 | USHORT usOemScanCode = iScanCode;
|
---|
181 | ULONG ulOemScanCodeDeadKeyInfo = 0;
|
---|
182 | USHORT fOemScanCodeShiftState = 0;
|
---|
183 | USHORT fOemScanCodeRc = WinTranslateChar2(0, &usOemScanCode, &ulOemScanCodeDeadKeyInfo, TC_SCANTOOEMSCAN, &fOemScanCodeShiftState);
|
---|
184 | if (usOemScanCode) {
|
---|
185 | printf("%3d/%#04x: %04x %lx %04x %04x\n",
|
---|
186 | iScanCode, iScanCode,
|
---|
187 | usOemScanCode, ulOemScanCodeDeadKeyInfo, fOemScanCodeShiftState, fOemScanCodeRc);
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | printf("\n"
|
---|
192 | "\n"
|
---|
193 | "\n"
|
---|
194 | "oem scan code -> scan code\n");
|
---|
195 | for (unsigned iOemScanCode = 0; iOemScanCode < 256; iOemScanCode++) {
|
---|
196 | USHORT usScanCode = iOemScanCode;
|
---|
197 | ULONG ulScanCodeDeadKeyInfo = 0;
|
---|
198 | USHORT fScanCodeShiftState = 0;
|
---|
199 | USHORT fScanCodeRc = WinTranslateChar2(0, &usScanCode, &ulScanCodeDeadKeyInfo, TC_OEMSCANTOSCAN, &fScanCodeShiftState);
|
---|
200 | if (usScanCode) {
|
---|
201 | printf("%3d/%#04x: %04x %lx %04x %04x\n",
|
---|
202 | iOemScanCode, iOemScanCode,
|
---|
203 | usScanCode, ulScanCodeDeadKeyInfo, fScanCodeShiftState, fScanCodeRc);
|
---|
204 | }
|
---|
205 | }
|
---|
206 |
|
---|
207 | return 0;
|
---|
208 | }
|
---|
209 |
|
---|