3 # FreeRDP: A Remote Desktop Protocol client.
4 # XKB database conversion script
6 # Copyright 2009 Marc-Andre Moreau <marcandre.moreau@gmail.com>
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
22 # Script to export XKB configuration files to keycode -> virtual key code keymaps that are
23 # easy to use in FreeRDP. This makes keymap maintenance easier to make as all bugs can
24 # simply be reported to the XKB Configuration Database project, and then this script can
25 # be used to export newer (and fixed) version of the XKB Configuration Database.
41 "AE11" => "VK_OEM_MINUS",
42 "AE12" => "VK_OEM_PLUS",
70 "AB00" => "VK_LSHIFT",
78 "AB08" => "VK_OEM_COMMA",
79 "AB09" => "VK_OEM_PERIOD",
81 "AB11" => "VK_ABNT_C1",
108 "KP0" => "VK_NUMPAD0",
109 "KP1" => "VK_NUMPAD1",
110 "KP2" => "VK_NUMPAD2",
111 "KP3" => "VK_NUMPAD3",
112 "KP4" => "VK_NUMPAD4",
113 "KP5" => "VK_NUMPAD5",
114 "KP6" => "VK_NUMPAD6",
115 "KP7" => "VK_NUMPAD7",
116 "KP8" => "VK_NUMPAD8",
117 "KP9" => "VK_NUMPAD9",
119 "KPDV" => "VK_DIVIDE",
120 "KPMU" => "VK_MULTIPLY",
121 "KPSU" => "VK_SUBTRACT",
123 "KPDL" => "VK_DECIMAL",
124 "KPEN" => "VK_RETURN",
126 "RTRN" => "VK_RETURN",
127 "SPCE" => "VK_SPACE",
129 "BKSL" => "VK_OEM_5",
130 "LSGT" => "VK_OEM_102",
131 "ESC" => "VK_ESCAPE",
132 "TLDE" => "VK_OEM_3",
133 "CAPS" => "VK_CAPITAL",
135 "LFSH" => "VK_LSHIFT",
136 "RTSH" => "VK_RSHIFT",
137 "LCTL" => "VK_LCONTROL",
138 "RCTL" => "VK_RCONTROL",
141 "LALT" => "VK_LMENU",
142 "RALT" => "VK_RMENU",
148 "RGHT" => "VK_RIGHT",
149 "INS" => "VK_INSERT",
150 "DELE" => "VK_DELETE",
151 "PGUP" => "VK_PRIOR",
155 "PAUS" => "VK_PAUSE",
156 "NMLK" => "VK_NUMLOCK",
157 "SCLK" => "VK_SCROLL",
159 # This page helps understanding the keys that follow:
160 # http://www.stanford.edu/class/cs140/projects/pintos/specs/kbd/scancodes-7.html
162 "KANJ" => "VK_KANJI",
163 "HANJ" => "VK_HANJA",
164 "MUHE" => "VK_NONCONVERT",
166 "PRSC" => "VK_SNAPSHOT",
168 "KPF1" => "VK_NUMLOCK",
169 "KPF2" => "VK_DIVIDE",
170 "KPF3" => "VK_MULTIPLY",
171 "KPF4" => "VK_SUBTRACT",
175 "SELE" => "VK_SELECT",
177 # We can ignore LDM (Lock Down Modifier)
178 # What are LCMP/RCMP?
187 $inDir = getcwd() . "/";
189 } elsif(@ARGV == 1) {
191 $outDir = getcwd() . "/";
192 } elsif(@ARGV == 2) {
196 print "Error: Too many arguments\n" .
198 "perl xkb.pl <XKB Directory>\n" .
199 "perl xkb.pl <XKB Directory> <Output Directory>\n\n" .
200 "In Linux, the XKB directory usually is /usr/share/X11/xkb/\n" .
201 "The latest version of XKB can always be downloaded at:\n" .
202 "http://freedesktop.org/wiki/Software/XKeyboardConfig\n";
208 open("SPEC", $inDir . "xkeyboard-config.spec");
211 while($line = <SPEC>) {
212 if($line =~ m/Version:\s+(.\..)/) {
213 $xkbVersion = "version $1";
217 # Create directory if it does not exists
219 mkdir $outDir or die("Error: Can't create directory $outDir\n");
222 open("KCD", $inDir . "keycodes/keycodes.dir") or die("Error: Can't open $inDir" . "keycodes/keycodes.dir\n");
225 while($line = <KCD>) {
226 if($line =~ m/........ -------- (.+)\((.+)\)/) {
227 if($1 ne $previousFile) {
228 push(@keymapFiles, $1);
235 foreach $keymapFile (@keymapFiles) {
237 print "File $keymapFile:\n";
239 @directories = split(/\//, $keymapFile);
240 splice(@directories, @directories - 1, 1);
242 if(@directories > 0) {
243 $directory = $outDir;
244 for($i = 0; $i < @directories; $i++) {
245 $directory .= $directories[$i] . "/";
246 if(not -e $directory) {
247 mkdir $directory or die("Can't create directory $directory\n");
252 open("IN", $inDir . "keycodes/" . $keymapFile);
253 open("OUT", ">" . "$outDir" . $keymapFile);
255 print OUT "# This file was generated with xkb.pl\n";
256 print OUT "# and is based on the X Keyboard Configuration Database $xkbVersion\n";
257 print OUT "# Please use xkb.pl to re-export newer versions of XKB\n";
260 while($line = <IN>) {
261 if($line =~ m/xkb_keycodes \"(\w+)\"/) {
263 print "Exporting \"$1\"\n";
264 print OUT "keyboard \"$1\"";
267 while($line = <IN>) {
268 if($line =~ m/include\W+\"(.+)\"/) {
269 print OUT "\n: extends \"$1\"";
277 while($line = <IN>) {
278 if($line =~ m/<(\w{1,4})>\W+=\W+(\w+);/) {
279 if($sym2virt{$1} ne undef) {
280 $vkcode = $sym2virt{$1};
281 print OUT "\t$vkcode";
283 if(length($vkcode) < 8) {
286 print OUT "\t<$2>\n";
288 # If undef, then this symbolic key code is
289 # missing from the sym2virt hash table
290 # print "\t$1\t$2\n";
292 } elsif($line =~ m/};/) {