1#include <winpr/input.h>
3static bool testKeyboardType(
enum WINPR_KBD_TYPE type, DWORD flag)
5 for (DWORD x = 0; x < 0x100; x++)
7 const DWORD vk = GetVirtualKeyCodeFromVirtualScanCode(x | flag, type);
16 const DWORD sc = GetVirtualScanCodeFromVirtualKeyCode(vk | flag, type);
19 if ((sc != 0) && (vk != VK_NONE))
21 DWORD buffer[256] = WINPR_C_ARRAY_INIT;
22 const DWORD count = GetVirtualScanCodesFromVirtualKeyCode(vk | flag, type, buffer,
26 for (DWORD i = 0; i < count; i++)
28 const DWORD cur = buffer[i];
37 printf(
"[%" PRIu32
"]: got %" PRIu32
", expected %" PRIu32, type, sc, x);
41 else if ((sc == 0) && (vk == VK_NONE))
46 printf(
"[%" PRIu32
"]: got %" PRIu32
", expected %" PRIu32, type, sc, x);
54static bool testKeyboardTypes(
enum WINPR_KBD_TYPE type)
56 if (!testKeyboardType(type, 0))
58 if (!testKeyboardType(type, KBDMULTIVK))
60 return testKeyboardType(type, KBDEXT);
63static bool testVKToKeycode(WINPR_KEYCODE_TYPE type)
66 for (DWORD x = 0; x <= 0x100; x++)
68 const DWORD vkc = GetVirtualKeyCodeFromKeycode(x, type);
69 const DWORD kc = GetKeycodeFromVirtualKeyCode(vkc, type);
72 if (!((kc == 0) && (vkc == VK_NONE)))
74 DWORD keycodes[0x100] = WINPR_C_ARRAY_INIT;
76 GetKeycodesFromVirtualKeyCode(vkc, type, keycodes, ARRAYSIZE(keycodes));
78 for (DWORD y = 0; y < count; y++)
91static bool testVKToKeycodes(
void)
93 const WINPR_KEYCODE_TYPE types[] = { WINPR_KEYCODE_TYPE_NONE, WINPR_KEYCODE_TYPE_APPLE,
94 WINPR_KEYCODE_TYPE_EVDEV, WINPR_KEYCODE_TYPE_XKB };
96 for (
size_t x = 0; x < ARRAYSIZE(types); x++)
98 const WINPR_KEYCODE_TYPE type = types[x];
99 if (!testVKToKeycode(type))
105int TestScancode(WINPR_ATTR_UNUSED
int argc, WINPR_ATTR_UNUSED
char* argv[])
107 if (!testVKToKeycodes())
110 const enum WINPR_KBD_TYPE types[] = { WINPR_KBD_TYPE_IBM_PC_XT, WINPR_KBD_TYPE_OLIVETTI_ICO,
111 WINPR_KBD_TYPE_IBM_PC_AT, WINPR_KBD_TYPE_IBM_ENHANCED,
112 WINPR_KBD_TYPE_NOKIA_1050, WINPR_KBD_TYPE_NOKIA_9140,
113 WINPR_KBD_TYPE_JAPANESE, WINPR_KBD_TYPE_KOREAN };
116 for (
size_t x = 0; x < ARRAYSIZE(types); x++)
118 const enum WINPR_KBD_TYPE type = types[x];
119 if (!testKeyboardTypes(type))