|
Packit Service |
50ad14 |
/*
|
|
Packit Service |
50ad14 |
* call: getkeycodes
|
|
Packit Service |
50ad14 |
*
|
|
Packit Service |
50ad14 |
* aeb, 941108
|
|
Packit Service |
50ad14 |
*/
|
|
Packit Service |
50ad14 |
#include "config.h"
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
#include <errno.h>
|
|
Packit Service |
50ad14 |
#include <stdio.h>
|
|
Packit Service |
50ad14 |
#include <stdlib.h>
|
|
Packit Service |
50ad14 |
#include <fcntl.h>
|
|
Packit Service |
50ad14 |
#include <sys/ioctl.h>
|
|
Packit Service |
50ad14 |
#include <linux/kd.h>
|
|
Packit Service |
50ad14 |
#include "getfd.h"
|
|
Packit Service |
50ad14 |
#include "nls.h"
|
|
Packit Service |
50ad14 |
#include "version.h"
|
|
Packit Service |
50ad14 |
#include "kbd_error.h"
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
static void __attribute__((noreturn))
|
|
Packit Service |
50ad14 |
usage(void)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
fprintf(stderr, _("usage: getkeycodes\n"));
|
|
Packit Service |
50ad14 |
exit(EXIT_FAILURE);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
int main(int argc, char **argv)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
int fd;
|
|
Packit Service |
50ad14 |
unsigned int sc, sc0;
|
|
Packit Service |
50ad14 |
struct kbkeycode a;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
set_progname(argv[0]);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
setlocale(LC_ALL, "");
|
|
Packit Service |
50ad14 |
bindtextdomain(PACKAGE_NAME, LOCALEDIR);
|
|
Packit Service |
50ad14 |
textdomain(PACKAGE_NAME);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (argc == 2 && !strcmp(argv[1], "-V"))
|
|
Packit Service |
50ad14 |
print_version_and_exit();
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (argc != 1)
|
|
Packit Service |
50ad14 |
usage();
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if ((fd = getfd(NULL)) < 0)
|
|
Packit Service |
50ad14 |
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
/* Old kernels don't support changing scancodes below SC_LIM. */
|
|
Packit Service |
50ad14 |
a.scancode = 0;
|
|
Packit Service |
50ad14 |
a.keycode = 0;
|
|
Packit Service |
50ad14 |
if (ioctl(fd, KDGETKEYCODE, &a)) {
|
|
Packit Service |
50ad14 |
sc0 = 89;
|
|
Packit Service |
50ad14 |
} else
|
|
Packit Service |
50ad14 |
for (sc0 = 1; sc0 <= 88; sc0++) {
|
|
Packit Service |
50ad14 |
a.scancode = sc0;
|
|
Packit Service |
50ad14 |
a.keycode = 0;
|
|
Packit Service |
50ad14 |
if (ioctl(fd, KDGETKEYCODE, &a) || a.keycode != sc0)
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
printf(_("Plain scancodes xx (hex) versus keycodes (dec)\n"));
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (sc0 == 89) {
|
|
Packit Service |
50ad14 |
printf(_("0 is an error; "
|
|
Packit Service |
50ad14 |
"for 1-88 (0x01-0x58) scancode equals keycode\n"));
|
|
Packit Service |
50ad14 |
} else if (sc0 > 1) {
|
|
Packit Service |
50ad14 |
printf(_("for 1-%d (0x01-0x%02x) scancode equals keycode\n"),
|
|
Packit Service |
50ad14 |
sc0 - 1, sc0 - 1);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
for (sc = (sc0 & ~7); sc < 256; sc++) {
|
|
Packit Service |
50ad14 |
if (sc == 128)
|
|
Packit Service |
50ad14 |
printf(_("\n\nEscaped scancodes e0 xx (hex)\n"));
|
|
Packit Service |
50ad14 |
if (sc % 8 == 0) {
|
|
Packit Service |
50ad14 |
if (sc < 128)
|
|
Packit Service |
50ad14 |
printf("\n 0x%02x: ", sc);
|
|
Packit Service |
50ad14 |
else
|
|
Packit Service |
50ad14 |
printf("\ne0 %02x: ", sc - 128);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (sc < sc0) {
|
|
Packit Service |
50ad14 |
printf(" %3d", sc);
|
|
Packit Service |
50ad14 |
continue;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
a.scancode = sc;
|
|
Packit Service |
50ad14 |
a.keycode = 0;
|
|
Packit Service |
50ad14 |
if (ioctl(fd, KDGETKEYCODE, &a) == 0) {
|
|
Packit Service |
50ad14 |
printf(" %3d", a.keycode);
|
|
Packit Service |
50ad14 |
continue;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
if (errno == EINVAL) {
|
|
Packit Service |
50ad14 |
printf(" -");
|
|
Packit Service |
50ad14 |
continue;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
kbd_error(EXIT_FAILURE, errno, _("failed to get keycode for scancode 0x%x: "
|
|
Packit Service |
50ad14 |
"ioctl KDGETKEYCODE"),
|
|
Packit Service |
50ad14 |
sc);
|
|
Packit Service |
50ad14 |
exit(1);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
printf("\n");
|
|
Packit Service |
50ad14 |
return EXIT_SUCCESS;
|
|
Packit Service |
50ad14 |
}
|