Skip to content
Newer
Older
100755 59 lines (48 sloc) 877 Bytes
e73565d @ice799 Initial checkin from http://c-skills.blogspot.com/2007/05/injectso.html
authored Jul 31, 2010
1 #!/usr/bin/perl -w
2
3
4 open(I, "dumpkeys|") or die $!;
5 open(O, ">keytab.h") or die $!;
6
7 print O<<EOF;
8 #ifndef __keytab_h__
9 #define __keytab_h__
10
11 char *keytable[512] = {
12 EOF
13
14 my %keytab = ();
15 my %name2char = (
16 "one" => "1",
17 "two" => "2",
18 "three" => "3",
19 "four" => "4",
20 "five" => "5",
21 "six" => "6",
22 "seven" => "7",
23 "eight" => "8",
24 "nine" => "9",
25 "zero" => "0",
26
27 "minus" => "-",
28 "plus" => "+",
29 "period" => ".",
30 "space" => " ",
31 );
32
33 while(<I>) {
34 if (/keycode\s+(\d+)\s+=\s+(\S+)\s+/) {
35 if (!defined $keytab{$1}) {
36 $keytab{$1} = $2;
37 }
38 }
39 }
40 close(I);
41
42 my $s = "";
43 foreach (keys %keytab) {
44 if (length($keytab{$_}) > 1) {
45 if (defined $name2char{$keytab{$_}}) {
46 $s = $name2char{$keytab{$_}};
47 } else {
48 $s = "<".$keytab{$_}.">";
49 }
50 } else {
51 $s = $keytab{$_};
52 }
53 print O "\t[$_] = \"".$s."\",\n";
54 }
55
56 print O "};\n#endif\n";
57 close(O);
58
Something went wrong with that request. Please try again.