XRDP – How To Make your keyboard “special keys” (Alt+Gr, Up,Down,..) working when using XRDP

xrdp_Kb_logo

 

Hello World,

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…

Problem Description

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.

Note :

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….) 

The Solution

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.

Note : 

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

 

Final Notes

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

See ya

References and Tools

 

 

 

69 thoughts on “XRDP – How To Make your keyboard “special keys” (Alt+Gr, Up,Down,..) working when using XRDP

  1. Thank you Tweety for bringing to my attention this issue.

    This was really challenging to find information and to come up with a fix. 🙂

    Till next time
    see ya

  2. Great – all I needed to do was copy the UK English keyboard layout file into the xrdp directory and my problems were solved. Now get UK English rather than US English.

    Note the link to the UK English keyboard is broken, but got it OK from the blog entry that you also link to.

    It does surprise me that the xrdp or Ubuntu maintainers have not included such common keyboard layouts by default.

  3. Hello Stephan,

    Thank you for the input and for notifying me about the broken link
    I’ll fix that as soon as possible

    Till next time
    See ya

  4. Unfortunatelly, the file km-0416.ini (brazilian portuguese aka ABNT2) found in the location indicated is just the default file which still needs to be fixed. I am working on it, following your instructions, to come up with a fix. When I fix it I will publish here as you requested. Thanks for this very helpful article.

  5. Hey Lucas;

    Thank your for your feedback and thank you for sharing your work as well. It would be great to have this additional keyboard layout.

    Till next time

    See ya

  6. Thx for the guide.. i have made a Danish version (km-0406.ini)… contact me on mail so i can send it to you 🙂

  7. Lucas Amorim,

    Como eu faço para baixar esse arquivo de configuração do teclado (km-0416.ini), que você criou!?

    Obrigado.

  8. Thank you, Griffon!!

    I don’t speak english very well too, but this file is identical the file km-0416.ini i generate with the command sudo xrdp-genkeymap /etc/xrdp/km-0416.ini but i have problems with some keys for example the key / . I guess Lucas Amorin improve this file, but no. How i can remap the / key?

  9. Oi Sergio,

    Eu ainda não o fiz. Tenho que fazer isso no meu tempo livre, que ultimamente tem sido raro. Assim que eu o fizer, publicarei aqui.
    Obrigado!

    Hello Sergio,

    I still didn’t accomplish that. I have to do it during my free time, which is a rare thing lately. As soon as I make it, I will publish it here.
    Thanks!

  10. Hey Lucas,

    Thank you for your answer…. Now I got it….Sergio wants the corrected version of the km file for portuguese layout
    Whenever you are ready with the km file, just let me know (write me a comment) and I’ll get in touch with you so I can publish the file
    Thank you for your time and for sharing your work with other people

    this is so great

    Till next time

    See ua

  11. Thank you for this helpfull post.
    Now i can contact my Ubuntu from Windows with my Belgium Dutch keyboard.

    Greetings from Puurs

  12. Hey Kristof,

    Graag gedaan…. Ik ben blij dat die post was nuttige voor jou. (My Duthc is not too bad hein….) :-p

    Thank for the visit and the feedback

    Till Next Time
    See ya

  13. Hej
    Very usefull guide. I wonder if there is a way to have a KM-XXXX.ini file depends on chosen keyboard layout. I have mutil user system in which users make rdesktop connection with differend keyboard layout. They all get US keyboard layout which is not usable with other keyboard layout. But if KM-xxx.ini file could be loaded from users home directory in stead of /etc/xrdp/ so it could be wonderfull. something like linking to ~/${USER}/km-0409.ini . Any help regarding this matter? Thanks!

  14. Hello Dariosh,

    To answer your question, I have no clue. I will need to have a look on what possible to do here…but to be honest given my personal situation at the moment and my work I’ll have no time in the near future to have a look at it…

    IF I have some time, I’ll try to check and see if we can come up with something (NO GUARANTEE)

    Till next Time
    See ya

  15. I miss something: what should I change to force the session to chose the mapping for a specific country to use?

  16. Hello Dwaltz,

    I’m assuming that you want to use another language mapping than english keyboard. if you need to set for example italian keyboard layout, you will have to modify the startwm.sh file

    just after the comment lines (#), you can add the following code

    if [ -r /etc/default/locale ]; then
    . /etc/default/locale
    export LANG LANGUAGE
    fi

    We assume that you have a locale file configured and listing the languages you want to use

    restart the xrdp service and give it a try (check the content of /etc/default/locale)

    Hope this help

    Till next time

    See ya

  17. Hi Griffon,

    Thanks for the excellent how-to articles.

    I am just posting a comment here to add some additional info for Xrdp users — if you are having keyboard mapping problems similar to those ones that Griffon is noting, /but/ your /etc/xrdp/km-xxxx.ini file appears to be correct — you should also investigate keymappings your X window manager may have established.

    The problem I was having is that Cntl-D was getting captured by the window manager (metacity in my case) and it’s default action is to “show desktop” — thus I needed to modify metacity’s keyboard mapping settings per..

    http://ubuntuforums.org/showthread.php?t=1595871

    ..rather than make any fixes to my /etc/xrdp/km-0409.ini (US english) file.

    I hope this helps,

    =JeffH

  18. Hello JeffH,

    Thank you for sharing this additional information.. I’m sure that this can be useful to people.
    Thank you for the visit and your comments…

    till next time
    see ya

  19. Hi,

    Thanks for this tutorial which got me started.

    I however could not manage to make my specific keymap load for whatever reason (using a bluetooth french keyboard locally to administer a mint VM), then searched some more.
    It so happens that the DEV branch of xrdp now generates a `xrdp_keyboard.ini` file in which makes all of this much more easy. I pasted it here : http://pastebin.com/j4cnet2S

    (this http://sourceforge.net/p/xrdp/mailman/message/32719395/ put me on track)

  20. Hello Pilow,

    Thank you very much for sharing the information. indeed, It seems that there are some changes in the way the keyboard is handled now…..
    With the next release of Ubuntu 14.10, we will update the posts in order to reflect the changes.

    Thank for the visit and sharing your knowledge…. thumbs up

    Till next time
    See ya

  21. Lucas, desde o ano passado você não enviou o arquivo km-0416.ini. Por favor, envie logo, pois estou desesperado.
    Obrigado!

  22. Hello there,
    yes indeed, thanks to our reader that contribute and that share the info around the world

    Thank for the visit

    Till next time
    see ya

  23. Thanks a lot. I’m on a Mac with Yosemite and trying to connect to Ubuntu 12.04 via xrdp. After MacOSX update, I couldn’t generate the character ` anymore on the remote machine. Your post helped to me solve it.

  24. Hey Cristian,

    Thank you for the visit. We happy to see that this post is still helping people out there.
    Do not hesitate to come back and visit us to get and share information about xrdp

    Till next time
    See ya

  25. Griffon, estava precisando do arquivo km-0416.ini já editado, que Lucas Amorim disse que te enviava e você publicaria.. porém, ele ainda não te enviou o arquivo. Por sorte, consegui editar o arquivo e o mesmo está quase perfeito. Assim que terminar, eu quero te enviar 🙂

  26. Hey Wesly

    (sorry for my bad Brazilian language )

    não há problema, se você tiver o arquivo , posso publicá-lo e disponibilizá-lo para outras pessoas

    Obrigado por compartilhar
    Até logo

  27. Griffon: Thank you for the instruction.
    Sune and Martin: Thankyou for the map-file.
    You all saved me a lot of work 🙂

    A small comment Griffon: Screenshot in step 3 do not fully reflect your instructions.
    – “setxkbmap” with and without the “-display” option
    Also in step 3
    – in the text you start changing path to the etc/xrdp folder – but later on your commands use paths relative to %home%.

  28. Hello Kim,

    thank for the visit and the comments. if we have some time, we will take into accounts your remarks and update the post accordingly
    See you around

    Till next time
    See ya

  29. Hi
    Ganesh here,
    I have small issues.
    I have installed Zorin OS and configured xrdp.also it is working fine with keyboard and mouse but when I access remote through thin client xrdp working fine with keyboard and mouse.Again inside linux I have taken rdp windows here keyboard not working but mouse are working fine..please help us this issue..

    Thanks.
    Ganesh..

  30. I finally had it with the missing keyborad map on my remote Raspian project….and I just spent the majority of a whole day trying to figure out how to get there.
    You have just saved my day.
    Danish Layout finally….thank you Sune.
    Thanks guys for sharing.
    /Mikael

  31. Hey Mikael,

    Happy to hear that this post is really helping people 🙂
    Thank for sharing you experience with

    Till next time
    See ya

  32. Hello Griffon!
    How are you?
    I too need the brazilian right KM file. I try to use it, this antique km-0416 but it is very incomplete.
    I try to generate it how you show here. So, very hard. I never do this before.

    Hey Brazilians! Do you make some new KM file?

    Great webpage and thanks

  33. Hello There

    Thank you for the feedback
    Thank you for providing useful information and needs for new km files

    Till next time
    See ya

  34. Hi Griffon,

    I’ m using your km-0813.ini file. This file works almost perfectly, but for one key : the Tab key. For some reason, I can’t seem to get it to work. I followed your guide and I have got this :

    Console map:
    23 0xff09 (Tab) 0xfe20 (ISO_Left_Tab) 0xff09 (Tab) 0xfe20 (ISO_Left_Tab)
    66 0xffe5 (Caps_Lock) 0x0000 (NoSymbol) 0xffe5 (Caps_Lock)
    Remote map:
    23 0x0036 (6) 0x005e (asciicircum)
    66 0xff09 (Tab)
    km-0813.ini:
    Key23=65289:9
    Key66=65509:0

    I tried copying the value of Key66 to Key23. The behaviour changes, but tab still doesn’t work.

    It took me some time to figure out that it wasn’t a problem with the bash autocomplete …

    FYI, xrdp runs in a docker container on my machine. So the Console map comes from the host’s console and the Remote map from xrdp in docker. I connect with xfreerdp.

    Am I doing something wrong ?

    Thanks, Peter.

  35. Hi! Thank you very much for all this useful information. With your tips I was able to get xrdp working correctly on my machine with an UK keyboard layout. It happens that the file you suggested (km-0809.ini from Components-part Blog) was not working 100% for me. Some keys were not correctly mapped, so I changed them and generated my final working file.
    I would like to upload it, but I feel the best place to have it it’s your webpage. Get in touch with me so I can pass you the file. Thank you.

  36. @Nino,
    Check you email and you can see how we can proceed to make the file available on this blog
    Thank you for the positive feedback and the work performed

    Till next time
    See ya

  37. Hi!
    Impressive blog entry thank you.
    I was having problems with some Alt Gr key combinations with may Spanish layout keyboard in a xrdp+Debian+Windows7 Client environment so I tried to follow your procedure. But soon I realized my key mapping was OK.
    It finally was fixed removing in my Windows 7 machine the English Keyboard which was added in addition to the default Spanish one. I don’t know the reason but somehow it worked so I share it here…

    Regards
    Miguel

  38. @Miguel,

    Thank you for sharing your experience and findings….We will try to integrate your information and all the one received lately in order to update and improve our XRDP posts

    Till next time
    See ya

  39. There is the configuration for Portuguese (km-0416.ini) please post as soon as posible:
    Aqui está a configuração para Português (km-0416.ini), por favor poste o mais breve possivel:

    https://gist.github.com/maxwelleite/54f7141513b18ad63e90b956ce5badce/raw/8a6ab91aad48db329fde8ec6a8f27eaf94dcfcb6/%2520km-0416.ini

    I not the author, I found on:
    Não sou o autor, encontrei em:
    http://amartinstechnet.blogspot.com.br/2016/09/configurar-teclado-lxde-abnt2-x11rdp.html

    I tested a little, but is very functional. If have any fix/sugestion do on gist:
    Eu testei pouco, mas está muito funcional. Se tem alguma correção/sugestão, faça pelo gist:
    https://gist.github.com/maxwelleite/54f7141513b18ad63e90b956ce5badce
    Thank you for the help, Griffon!

Leave a Reply