3
# rdesktop: A Remote Desktop Protocol client.
4
# User interface services - XKB Configuration Files Exporter
6
# Copyright (C) Marc-Andre Moreau <marcandre.moreau@gmail.com> 2009
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
# Script to export XKB configuration files to keycode -> virtual key code keymaps that are
24
# easy to use in rdesktop. This makes keymap maintenance easier to make as all bugs can
25
# simply be reported to the XKB Configuration Database project, and then this script can
26
# be used to export newer (and fixed) version of the XKB Configuration Database.
42
"AE11" => "VK_OEM_MINUS",
43
"AE12" => "VK_OEM_PLUS",
71
"AB00" => "VK_LSHIFT",
79
"AB08" => "VK_OEM_COMMA",
80
"AB09" => "VK_OEM_PERIOD",
82
"AB11" => "VK_RSHIFT",
109
"KP0" => "VK_NUMPAD0",
110
"KP1" => "VK_NUMPAD1",
111
"KP2" => "VK_NUMPAD2",
112
"KP3" => "VK_NUMPAD3",
113
"KP4" => "VK_NUMPAD4",
114
"KP5" => "VK_NUMPAD5",
115
"KP6" => "VK_NUMPAD6",
116
"KP7" => "VK_NUMPAD7",
117
"KP8" => "VK_NUMPAD8",
118
"KP9" => "VK_NUMPAD9",
120
"KPDV" => "VK_DIVIDE",
121
"KPMU" => "VK_MULTIPLY",
122
"KPSU" => "VK_SUBTRACT",
124
"KPDL" => "VK_DECIMAL",
125
"KPEN" => "VK_RETURN",
127
"RTRN" => "VK_RETURN",
128
"SPCE" => "VK_SPACE",
130
"BKSL" => "VK_OEM_5",
131
"LSGT" => "VK_OEM_102",
132
"ESC" => "VK_ESCAPE",
133
"TLDE" => "VK_OEM_3",
134
"CAPS" => "VK_CAPITAL",
136
"LFSH" => "VK_LSHIFT",
137
"RTSH" => "VK_RSHIFT",
138
"LCTL" => "VK_LCONTROL",
139
"RCTL" => "VK_RCONTROL",
142
"LALT" => "VK_LMENU",
143
"RALT" => "VK_RMENU",
149
"RGHT" => "VK_RIGHT",
150
"INS" => "VK_INSERT",
151
"DELE" => "VK_DELETE",
152
"PGUP" => "VK_PRIOR",
156
"PAUS" => "VK_PAUSE",
157
"NMLK" => "VK_NUMLOCK",
158
"SCLK" => "VK_SCROLL",
160
# This page helps understanding the keys that follow:
161
# http://www.stanford.edu/class/cs140/projects/pintos/specs/kbd/scancodes-7.html
163
"KANJ" => "VK_KANJI",
164
"HANJ" => "VK_HANJA",
165
"MUHE" => "VK_NONCONVERT",
167
"PRSC" => "VK_SNAPSHOT",
169
"KPF1" => "VK_NUMLOCK",
170
"KPF2" => "VK_DIVIDE",
171
"KPF3" => "VK_MULTIPLY",
172
"KPF4" => "VK_SUBTRACT",
176
"SELE" => "VK_SELECT",
178
# We can ignore LDM (Lock Down Modifier)
179
# What are LCMP/RCMP?
188
$inDir = getcwd() . "/";
190
} elsif(@ARGV == 1) {
192
$outDir = getcwd() . "/";
193
} elsif(@ARGV == 2) {
197
print "Error: Too many arguments\n" .
199
"perl xkb.pl <XKB Directory>\n" .
200
"perl xkb.pl <XKB Directory> <Output Directory>\n\n" .
201
"In Linux, the XKB directory usually is /usr/share/X11/xkb/\n" .
202
"The latest version of XKB can always be downloaded at:\n" .
203
"http://freedesktop.org/wiki/Software/XKeyboardConfig\n";
209
open("SPEC", $inDir . "xkeyboard-config.spec");
212
while($line = <SPEC>) {
213
if($line =~ m/Version:\s+(.\..)/) {
214
$xkbVersion = "version $1";
218
# Create directory if it does not exists
220
mkdir $outDir or die("Error: Can't create directory $outDir\n");
223
open("KCD", $inDir . "keycodes/keycodes.dir") or die("Error: Can't open $inDir" . "keycodes/keycodes.dir\n");
226
while($line = <KCD>) {
227
if($line =~ m/........ -------- (.+)\((.+)\)/) {
228
if($1 ne $previousFile) {
229
push(@keymapFiles, $1);
236
foreach $keymapFile (@keymapFiles) {
238
print "File $keymapFile:\n";
240
@directories = split(/\//, $keymapFile);
241
splice(@directories, @directories - 1, 1);
243
if(@directories > 0) {
244
$directory = $outDir;
245
for($i = 0; $i < @directories; $i++) {
246
$directory .= $directories[$i] . "/";
247
if(not -e $directory) {
248
mkdir $directory or die("Can't create directory $directory\n");
253
open("IN", $inDir . "keycodes/" . $keymapFile);
254
open("OUT", ">" . "$outDir" . $keymapFile);
257
print OUT "# This file was generated with xkb.pl ($time)\n";
258
print OUT "# and is based on the X Keyboard Configuration Database $xkbVersion\n";
259
print OUT "# Please use xkb.pl to re-export newer versions of XKB\n";
262
while($line = <IN>) {
263
if($line =~ m/xkb_keycodes \"(\w+)\"/) {
265
print "Exporting \"$1\"\n";
266
print OUT "keyboard \"$1\"";
269
while($line = <IN>) {
270
if($line =~ m/include\W+\"(.+)\"/) {
271
print OUT "\n: extends \"$1\"";
279
while($line = <IN>) {
280
if($line =~ m/<(\w{1,4})>\W+=\W+(\w+);/) {
281
if($sym2virt{$1} ne undef) {
282
$vkcode = $sym2virt{$1};
283
print OUT "\t$vkcode";
285
if(length($vkcode) < 8) {
288
print OUT "\t<$2>\n";
290
# If undef, then this symbolic key code is
291
# missing from the sym2virt hash table
292
# print "\t$1\t$2\n";
294
} elsif($line =~ m/};/) {