VirtualBox

Ticket #10664: xkbtest.c

File xkbtest.c, 1.2 KB (added by Michael Thayer, 12 years ago)

Test programme for the key names provided by the XKB extension.

Line 
1#include <stdio.h>
2#include <errno.h>
3#include <X11/Xlib.h>
4#include <X11/XKBlib.h>
5
6int main()
7{
8 int major = XkbMajorVersion, minor = XkbMinorVersion;
9 XkbDescPtr pKBDesc;
10 Display *pDisplay = XkbOpenDisplay(NULL, NULL, NULL, &major, &minor,
11 NULL);
12 if (!pDisplay)
13 error(1, 0, "failed to open the display");
14 pKBDesc = XkbGetKeyboard(pDisplay, XkbAllComponentsMask, XkbUseCoreKbd);
15 if (!pKBDesc)
16 error(1, 0, "could not obtain keyboard descriptor");
17 if (XkbGetNames(pDisplay, XkbKeyNamesMask, pKBDesc) != Success)
18 error(1, 0, "could not update keyboard descriptor");
19 {
20 int i, j;
21 for (i = 0; i < 64; ++i)
22 {
23 for (j = 0; j < 4; ++j)
24 {
25 int index = i * 4 + j;
26 if (index < pKBDesc->max_key_code)
27 printf("%4d: %8.4s", index, &pKBDesc->names->keys->name[index * 4]);
28 if (index + 1 < pKBDesc->max_key_code)
29 printf(", ");
30 }
31 if (i * 4 < pKBDesc->max_key_code)
32 printf("\n");
33 }
34 }
35 XkbFreeNames(pKBDesc, XkbKeyNamesMask, True);
36 XkbFreeKeyboard(pKBDesc, XkbAllComponentsMask, True);
37 return 0;
38}

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy