aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2016-02-15 09:53:39 +0100
committerGerd Hoffmann <kraxel@redhat.com>2016-02-15 09:53:46 +0100
commit71253d8cb0a3824df1aa73f47631babf614b2702 (patch)
tree0a0470139898bf2b2d40b4946a87bfe6f46ae363
parent81be8b5dc9245546bf1af297d6e6a580143c5273 (diff)
downloadinput-71253d8cb0a3824df1aa73f47631babf614b2702.tar.gz
input-kbd: allow comments
based on a patch by Preston Crow.
-rw-r--r--input-kbd.c12
-rw-r--r--input-kbd.man8
2 files changed, 18 insertions, 2 deletions
diff --git a/input-kbd.c b/input-kbd.c
index 3f0be52..8dd4e68 100644
--- a/input-kbd.c
+++ b/input-kbd.c
@@ -125,11 +125,21 @@ static void kbd_map_print(FILE *fp, struct kbd_map *map, int complete)
static int kbd_map_parse(FILE *fp, struct kbd_map *map)
{
struct kbd_entry entry;
- char line[80],scancode[80],keycode[80];
+ char line[1024],scancode[80],keycode[80];
+ char *c;
int i;
int idx = 0;
while ((NULL != fgets(line,sizeof(line),fp)) && (idx < map->keys)) {
+ c = strchr(line,'#');
+ if (c)
+ *c = 0;
+ c = line;
+ while (*c == ' ' || *c == '\t')
+ c++;
+ if (!*c || *c == '\n')
+ continue; // Blank or comment line
+
if (2 != sscanf(line," %80s = %80s", scancode, keycode)) {
fprintf(stderr,"parse error: %s",line);
return -1;
diff --git a/input-kbd.man b/input-kbd.man
index afe723b..1ecd0e8 100644
--- a/input-kbd.man
+++ b/input-kbd.man
@@ -45,10 +45,16 @@ The index of the input device to use (0 for /dev/input/event0 and so on).
.TP
\fB\-f\fR \fIfile\fR
Read a keyboard map from a file and reconfigure the device with this map.
+If the file name is '-' then stdin is used.
The map file uses the same format as the output of this command.
+Blank lines are ignored. A '#' character and anything following it on the same line are ignored as a comment.
+Scancodes and keycodes are decimal values unless proceeded by "0x" for hexadecimal.
+To remove a mapping entirely, set it to 0x00 (RESERVED).
Key names are also accepted instead of keycodes, like this:
.IP
0x0001 = KEY_F9
-
+.TP
+Be careful setting values from 0 to 9, as they will be parsed as the key symbols, not the decimal numbers. If you want to list a single-digit decimal keycode, specify it as a hexadecimal value to remove any ambiguity.
+
.SH AUTHOR
Gerd Hoffmann <kraxel@redhat.com>