Example #1
0
static void set_key(int fd, const char* scancode_str, const char* keyname)
{
	unsigned scancode;
	char *endptr;
	char t[105] = "KEY_UNKNOWN";
	const struct key *k;

	scancode = (unsigned) strtol(scancode_str, &endptr, 0);
	if (*endptr != '\0') {
		fprintf(stderr, "ERROR: Invalid scancode\n");
		exit(1);
	}

	snprintf(t, sizeof(t), "KEY_%s", keyname);

	if (!(k = lookup_key(t, strlen(t)))) {
		fprintf(stderr, "ERROR: Unknown key name '%s'\n", keyname);
		exit(1);
	}

	if (evdev_set_keycode(fd, scancode, k->id) < 0)
		fprintf(stderr, "setting scancode 0x%2X to key code %i failed\n", 
			scancode, k->id);
	else
		printf("setting scancode 0x%2X to key code %i\n", 
			scancode, k->id);
}
Example #2
0
static int merge_table(int fd, FILE *f) {
        int r = 0;
        int line = 0;

        while (!feof(f)) {
                char s[256], *p;
                unsigned scancode;
                int new_keycode, old_keycode;

                if (!fgets(s, sizeof(s), f))
                        break;

                line++;
                p = s+strspn(s, "\t ");
                if (*p == '#' || *p == '\n')
                        continue;

                if (sscanf(p, "%i %i", &scancode, &new_keycode) != 2) {
                        char t[105] = "KEY_UNKNOWN";
                        const struct key *k;

                        if (sscanf(p, "%i %100s", &scancode, t+4) != 2) {
                                fprintf(stderr, "WARNING: Parse failure at line %i, ignoring.\n", line);
                                r = -1;
                                continue;
                        }

                        if (!(k = lookup_key(t, strlen(t)))) {
                                fprintf(stderr, "WARNING: Unknown key '%s' at line %i, ignoring.\n", t, line);
                                r = -1;
                                continue;
                        }

                        new_keycode = k->id;
                }


                if ((old_keycode = evdev_get_keycode(fd, scancode, 0)) < 0) {
                        r = -1;
                        continue;
                }

                if (evdev_set_keycode(fd, scancode, new_keycode) < 0) {
                        r = -1;
                        continue;
                }

                if (new_keycode != old_keycode)
                        fprintf(stderr, "Remapped scancode 0x%02x to 0x%02x (prior: 0x%02x)\n",
                                scancode, new_keycode, old_keycode);
        }

        fclose(f);
        return r;
}