If you follow me, you probably know that I’m quite busy lately. Recently, I’ve received questions related about xrdp and the fact that the keyboard layout is not working as expected when remoting to the ubuntu machine even if you have run the xrdp-genkeymap utility. This problem seems to be quite common when working with xrdp and localized keyboards.
I didn’t had time to look into a proper solution. Till now ! I’ve spend my day off (Sunday) to have a look into the problem and try to come up with a solution….
Keep reading if you want to have a working keyboard when connecting via XRDP to your ubuntu machine…
We assume that you have installed the xrdp software using the instructions described here if you are using Ubuntu 12.10 or here if you are using Ubuntu 12.04. If this is the case, you should be able to perform a remote desktop connection into your Ubuntu from any Windows machines.
For adventurous users, you can try to manually install (or automate the install by using the referenced script) the lastest version xrdp software (Version 0.70 which is available at this location) by following the instructions described in part I, Part II and Part III
If your keyboard layout is not set to english, you know that when connecting to the ubuntu machine via XRDP your keyboard layout will not match. As described in our previous post, when you pass the credentials in the xRDP login box, the default keyboard layout is set to English. When you establish the connection, your remote session will also use the English keyboard layout.
To fix this issue, xrdp comes with a small utility (called xrdp-genkeymap) that allows you to change the keyboard layout to be used during the remote session. After running the utility (see here for instructions – Solving Keyboard layout problem section), you would normally think that everything should be working as expected.
So, you connect to your Ubuntu machine via XRDP, you open a text editor and you check that your keyboard layout is the correct one. As long as you do not use “special keys”, you should be fine. As soon as you start using arrows keys (Up, Down,Left,Right) or even key combinations (like Alt+Gr) to output the Euro Sign (€) or the at sign (@) for example, you will notice that your keyboard is not fully functional. (It almost unusable !!…Aargh….)
This problem was driving me crazy and I thought I would need to try and fix it. This approach worked for me and this might work for you. You might need to spend a lot of time fixing your keyboard layout.
In my situation, I have configured a Belgian French keyboard layout on my ubuntu machine and the xrdp software was installed accordingly. As described earlier, in order to make an xrdp connection and having the basic keyboard layout working, I’ve performed the following actions
Step 1 – Read xrdp guidance in order to create new key map files
You can find a short explanation about the xrdp key map file, how it’s generated and explain the section and values you will find inside the file. The xrdp key map file are named km-xxxx.ini where the xxxx is the hex number representing the keyboard layout you want to use
Step 2 – Find the Hex Number representing you keyboard layout
If you follow this link, you will reach a page that list the possible keyboard layout and their hex number. So, in my scenario, I want to use the Belgian French keyboard, I’ll need to generate a file called km-080c.ini using the xrdp-genkeymap utility
Step 3 – Run the xrdp-genkeymap tool to generate the km-080c.ini
- You go to the /etc/xrdp directory
- you issue the command setxkbmap -layout <%your layout%> to define which keyboard map/layout to use
- create a copy of the km-4090.ini file into the same directory. It seems that this is the default file used by xrdp to define the keyboard layout. You will need to use sudo in order to be able to write into the directory
- Check that you have a backup of your file by typing the dir or ls command
- update the file by issuing the following command sudo xrdp-genkeymap /etc/xrdp/km-080c.ini
click on Picture for better Resolution
Step 4 – Identify and compare the missing key strokes
At this stage, you should have a working basic keyboard. You will need to dump the keyboard layout from the console and from your remote session. At the console (no xrdp connection but locally on the system), type the following command to dump the keyboard layout
xmodmap -pk >ConsolekbLayout.txt
Perform an xrdp connection to your ubuntu, and in your remote session, perform the same operation i.e dump the keyboard layout
xmodmap -pk >RemoteKbLayout.txt
Step 5 – Update your km-xxx.ini file in order to reflect the keyboard layout in the Remote session
To illustrate the purpose, I will give an example. The key stroke Arrow left is not working in the remote session. To fix this, we will compare the key code and the key value of the Left key stroke in the files we have generated here above.
This screenshot shows the content of the ConsoleKbLayout.txt. You can see that the key Left is associated wit the key code 113 and has a Hex value of 0xff51.
click on Picture for better resolution
The screenshot below shows the content of the RemoteKbLayout.txt. You can see that the Key Left is associated with the key code 100 and has an Hex value of 0xff51
Click on Picture for Better resolution
The km-080c.ini file controls the keyboard layout in your remote session. If we open the km-080c.ini (Belgian French keyboard layout in my example), you will see that the value of the key113 is set to 65361 (which is the decimal value of 0xff51) which represent the arrow left key stroke when connecting at the console. However, in the remote session, the arrow left arrow is assigned to the key code 100. So, we need to copy the value found at the key code 113 and paste it at the key code 100.
Click on Picture for Better resolution
You will need to perform this operation for each key stroke that is not recognized in your remote session.
It would have been easier if you could generate the km-xxxx.ini file in the remote session but when you try to set the keyboard, you have an error returned
XKB extension not present on : xx:0
Click on Picture for Better resolution
And Voila ! We have solved the keyboard problem when used in conjunction with xrdp. As you can see, this can be a long process to remap correctly keyboard layouts. Hopefully for me, some people have already prepared and published valid keyboard layouts. You can find valid keyboard layouts at this location
The following keyboard are already available and should be working
- Belgian French – km-080c.ini
- Belgian Dutch – km-0813.ini
- US English – km-0409.ini
- French(France) – km-040c.ini
- German – km-0407.ini
- Italian – km-0410.ini
- Portuguese – km-0416.ini
- Russian – km-0419.ini
- Swedish – km-041d.ini
- German Swiss – km-0807.ini
If you wanna help…
If you have a working key map file for other keyboard layout than mentioned above, please submit a comment so I can get in touch with you or submit the file to the xrdp community directly. I’ll upload and attach the file to this post.
I already found (or users have provided me) these additional key map files
|English UK||km-0809.ini (from Components-part Blog)
km-0809_v1.1.ini (This is an updated version of the file provided by Nino Pereira. This file seems to correct some issues with the UK Keyboard layout.
|Spanish (Traditional Sort)||km-040a.ini (unknow source)|
|Danish||km-406.ini (Provided by Sune Nielsen)|
|km-406.ini_V1.1 (This is an updated version of the file provided by Sune Nielsen – The update has been provided by Martin Köster)|
|Portuguese||km-416.ini (File provided by Maxweil Leite|
Till Next Time
References and Tools