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

 

xrdp_kb0

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.

xrdp_kblayout_7

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

  xrdp_kblayout_6

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.

xrdpbk3

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

 

xrdpkb_10

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

 

 

 

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

  1. @Maxwel Leite,

    Thank you very much for you contribution…We will upload this file into the post and we hope that people would enjoy it

    Till next time
    See ya

  2. Hello. I copied the Maxweel Leite file (km-416.ini). How do I set which keyboard map to use? I made the following command: “setxkbmap -layout pt” but did not update. The arrow keys such as the left do not work. Thank you.

  3. It worked now. I disconnected from the remote connection and connected again and it worked. Please disregard the previous review. Thank you

  4. @Fabio,

    Please read full instructions…in Step 3, it’s mentioned that you need to use issue the following command :

    sudo xrdp-genkeymap /etc/xrdp/km-0xxx.ini

    Again, go through the post and read carefully each instruction provided…

    Hope this help
    Till next time
    See ya

  5. Hi Griffon,

    I am trying to get xrdp working with Ubuntu 16.04.2 and the gnome3 desktop.
    Your posts have helped a lot and apart from a few small things, I am pretty much in box.
    I am using a Norwegian keyboard (0414), but can you explain to me a few things.
    1) I downloaded the keyboard mapping from git, based on info in one of your blog posts. Why are these known mappings just not delivered as default ?
    2) I personally needed to copy the km-0414.ini mapping file to km-0409.ini to get things to work. Why is this necessary? Where is xrdp getting the info that I have a US system (which I do not). Or this this just some crappy default?

  6. @Ian,

    The keyboard issue is due to the fact that ubuntu 16.04 is using the older xrdp package (0.6-x). These issues have been solved in the xrdp package version 0.9.x where the xorgxrdp backend server component is used…. because xrdp has changed a little bit, we have to update our custom installation script for ubuntu 16.04,…if you can wait 1 or 2 weeks, we will be publishing the updated script for Ubuntu 16.04.x

    hope this help
    Till next time
    See ya

  7. If you don’t have a screen/keyboard to make the xrdp commands work,
    you can just download the file you need from the github page linked in this forum
    this one >>https://github.com/FreeRDP/xrdp/tree/master/instfiles

    then copy the contents of that file into the default file, which is the km-0409.ini file

    sudo cp “path to the downloaded file” /etc/xrdp/km-0409.ini
    sudo reboot

    after reboot you should have the keyboard working like you set it to work.

  8. @Szmore,

    thank you for the information and sharing it. we will try to add it into our list in a near future
    See you
    Till next time

  9. this one worked for Portuguese keyboard with accentuation ok as with ã

    [noshift]
    Key8=0:0
    Key9=65307:27
    Key10=49:49
    Key11=50:50
    Key12=51:51
    Key13=52:52
    Key14=53:53
    Key15=54:54
    Key16=55:55
    Key17=56:56
    Key18=57:57
    Key19=48:48
    Key20=39:39
    Key21=171:171
    Key22=65288:8
    Key23=65289:9
    Key24=113:113
    Key25=119:119
    Key26=101:101
    Key27=114:114
    Key28=116:116
    Key29=121:121
    Key30=117:117
    Key31=105:105
    Key32=111:111
    Key33=112:112
    Key34=43:43
    Key35=65105:180
    Key36=65293:13
    Key37=65507:0
    Key38=97:97
    Key39=115:115
    Key40=100:100
    Key41=102:102
    Key42=103:103
    Key43=104:104
    Key44=106:106
    Key45=107:107
    Key46=108:108
    Key47=231:231
    Key48=186:186
    Key49=92:92
    Key50=65505:0
    Key51=65107:126
    Key52=122:122
    Key53=120:120
    Key54=99:99
    Key55=118:118
    Key56=98:98
    Key57=110:110
    Key58=109:109
    Key59=44:44
    Key60=46:46
    Key61=45:45
    Key62=65506:0
    Key63=65450:42
    Key64=65513:0
    Key65=32:32
    Key66=65509:0
    Key67=65470:0
    Key68=65471:0
    Key69=65472:0
    Key70=65473:0
    Key71=65474:0
    Key72=65475:0
    Key73=65476:0
    Key74=65477:0
    Key75=65478:0
    Key76=65479:0
    Key77=65407:0
    Key78=65300:0
    Key79=65429:0
    Key80=65431:0
    Key81=65434:0
    Key82=65453:45
    Key83=65430:0
    Key84=65437:0
    Key85=65432:0
    Key86=65451:43
    Key87=65436:0
    Key88=65433:0
    Key89=65435:0
    Key90=65438:0
    Key91=65439:0
    Key92=65027:0
    Key93=0:0
    Key94=60:60
    Key95=65480:0
    Key96=65481:0
    Key97=0:0
    Key98=65318:0
    Key99=65317:0
    Key100=65315:0
    Key101=65319:0
    Key102=65314:0
    Key103=0:0
    Key104=65421:13
    Key105=65508:0
    Key106=65455:47
    Key107=65377:0
    Key108=65027:0
    Key109=65290:10
    Key110=65360:0
    Key111=65362:0
    Key112=65365:0
    Key113=65361:0
    Key114=65363:0
    Key115=65367:0
    Key116=65364:0
    Key117=65366:0
    Key118=65379:0
    Key119=65535:127
    Key120=0:0
    Key121=269025042:0
    Key122=269025041:0
    Key123=269025043:0
    Key124=269025066:0
    Key125=65469:61
    Key126=177:177
    Key127=65299:0
    Key128=269025098:0
    Key129=65454:46
    Key130=65329:0
    Key131=65332:0
    Key132=0:0
    Key133=65515:0
    Key134=65516:0
    Key135=65383:0
    Key136=65385:0
    Key137=65382:0

    [shift]
    Key8=0:0
    Key9=65307:27
    Key10=33:33
    Key11=34:34
    Key12=35:35
    Key13=36:36
    Key14=37:37
    Key15=38:38
    Key16=47:47
    Key17=40:40
    Key18=41:41
    Key19=61:61
    Key20=63:63
    Key21=187:187
    Key22=65288:8
    Key23=65056:0
    Key24=81:81
    Key25=87:87
    Key26=69:69
    Key27=82:82
    Key28=84:84
    Key29=89:89
    Key30=85:85
    Key31=73:73
    Key32=79:79
    Key33=80:80
    Key34=42:42
    Key35=65104:96
    Key36=65293:13
    Key37=65507:0
    Key38=65:65
    Key39=83:83
    Key40=68:68
    Key41=70:70
    Key42=71:71
    Key43=72:72
    Key44=74:74
    Key45=75:75
    Key46=76:76
    Key47=199:199
    Key48=170:170
    Key49=124:124
    Key50=65505:0
    Key51=65106:94
    Key52=90:90
    Key53=88:88
    Key54=67:67
    Key55=86:86
    Key56=66:66
    Key57=78:78
    Key58=77:77
    Key59=59:59
    Key60=58:58
    Key61=95:95
    Key62=65506:0
    Key63=65450:42
    Key64=65511:0
    Key65=32:32
    Key66=65509:0
    Key67=65470:0
    Key68=65471:0
    Key69=65472:0
    Key70=65473:0
    Key71=65474:0
    Key72=65475:0
    Key73=65476:0
    Key74=65477:0
    Key75=65478:0
    Key76=65479:0
    Key77=65407:0
    Key78=65300:0
    Key79=65463:55
    Key80=65464:56
    Key81=65465:57
    Key82=65453:45
    Key83=65460:52
    Key84=65461:53
    Key85=65462:54
    Key86=65451:43
    Key87=65457:49
    Key88=65458:50
    Key89=65459:51
    Key90=65456:48
    Key91=65454:46
    Key92=65027:0
    Key93=0:0
    Key94=62:62
    Key95=65480:0
    Key96=65481:0
    Key97=0:0
    Key98=65318:0
    Key99=65317:0
    Key100=65315:0
    Key101=65319:0
    Key102=65314:0
    Key103=0:0
    Key104=65421:13
    Key105=65508:0
    Key106=65455:47
    Key107=65377:0
    Key108=65027:0
    Key109=65290:10
    Key110=65360:0
    Key111=65362:0
    Key112=65365:0
    Key113=65361:0
    Key114=65363:0
    Key115=65367:0
    Key116=65364:0
    Key117=65366:0
    Key118=65379:0
    Key119=65535:127
    Key120=0:0
    Key121=269025042:0
    Key122=269025041:0
    Key123=269025043:0
    Key124=269025066:0
    Key125=65469:61
    Key126=177:177
    Key127=65299:0
    Key128=269025098:0
    Key129=65454:46
    Key130=65329:0
    Key131=65332:0
    Key132=0:0
    Key133=65515:0
    Key134=65516:0
    Key135=65383:0
    Key136=65385:0
    Key137=65382:0

    [altgr]
    Key8=0:0
    Key9=65307:27
    Key10=185:185
    Key11=64:64
    Key12=163:163
    Key13=167:167
    Key14=189:189
    Key15=172:172
    Key16=123:123
    Key17=91:91
    Key18=93:93
    Key19=125:125
    Key20=92:92
    Key21=65115:184
    Key22=65288:8
    Key23=65289:9
    Key24=64:64
    Key25=435:322
    Key26=8364:8364
    Key27=182:182
    Key28=956:359
    Key29=2299:8592
    Key30=2302:8595
    Key31=2301:8594
    Key32=248:248
    Key33=254:254
    Key34=65111:168
    Key35=65107:126
    Key36=65293:13
    Key37=65507:0
    Key38=230:230
    Key39=223:223
    Key40=240:240
    Key41=496:273
    Key42=959:331
    Key43=689:295
    Key44=65121:0
    Key45=930:312
    Key46=435:322
    Key47=65105:180
    Key48=65106:94
    Key49=172:172
    Key50=65505:0
    Key51=65104:96
    Key52=171:171
    Key53=187:187
    Key54=162:162
    Key55=2770:8220
    Key56=2771:8221
    Key57=110:110
    Key58=181:181
    Key59=2211:0
    Key60=183:183
    Key61=65120:0
    Key62=65506:0
    Key63=65450:42
    Key64=65513:0
    Key65=32:32
    Key66=65509:0
    Key67=65470:0
    Key68=65471:0
    Key69=65472:0
    Key70=65473:0
    Key71=65474:0
    Key72=65475:0
    Key73=65476:0
    Key74=65477:0
    Key75=65478:0
    Key76=65479:0
    Key77=65407:0
    Key78=65300:0
    Key79=65429:0
    Key80=65431:0
    Key81=65434:0
    Key82=65453:45
    Key83=65430:0
    Key84=65437:0
    Key85=65432:0
    Key86=65451:43
    Key87=65436:0
    Key88=65433:0
    Key89=65435:0
    Key90=65438:0
    Key91=65439:0
    Key92=65027:0
    Key93=0:0
    Key94=92:92
    Key95=65480:0
    Key96=65481:0
    Key97=0:0
    Key98=65318:0
    Key99=65317:0
    Key100=65315:0
    Key101=65319:0
    Key102=65314:0
    Key103=0:0
    Key104=65421:13
    Key105=65508:0
    Key106=65455:47
    Key107=65377:0
    Key108=65027:0
    Key109=65290:10
    Key110=65360:0
    Key111=65362:0
    Key112=65365:0
    Key113=65361:0
    Key114=65363:0
    Key115=65367:0
    Key116=65364:0
    Key117=65366:0
    Key118=65379:0
    Key119=65535:127
    Key120=0:0
    Key121=269025042:0
    Key122=269025041:0
    Key123=269025043:0
    Key124=269025066:0
    Key125=65469:61
    Key126=177:177
    Key127=65299:0
    Key128=269025098:0
    Key129=65454:46
    Key130=65329:0
    Key131=65332:0
    Key132=0:0
    Key133=65515:0
    Key134=65516:0
    Key135=65383:0
    Key136=65385:0
    Key137=65382:0

    [capslock]
    Key8=0:0
    Key9=65307:27
    Key10=49:49
    Key11=50:50
    Key12=51:51
    Key13=52:52
    Key14=53:53
    Key15=54:54
    Key16=55:55
    Key17=56:56
    Key18=57:57
    Key19=48:48
    Key20=39:39
    Key21=171:171
    Key22=65288:8
    Key23=65289:9
    Key24=81:81
    Key25=87:87
    Key26=69:69
    Key27=82:82
    Key28=84:84
    Key29=89:89
    Key30=85:85
    Key31=73:73
    Key32=79:79
    Key33=80:80
    Key34=43:43
    Key35=65105:180
    Key36=65293:13
    Key37=65507:0
    Key38=65:65
    Key39=83:83
    Key40=68:68
    Key41=70:70
    Key42=71:71
    Key43=72:72
    Key44=74:74
    Key45=75:75
    Key46=76:76
    Key47=199:199
    Key48=186:186
    Key49=92:92
    Key50=65505:0
    Key51=65107:126
    Key52=90:90
    Key53=88:88
    Key54=67:67
    Key55=86:86
    Key56=66:66
    Key57=78:78
    Key58=77:77
    Key59=44:44
    Key60=46:46
    Key61=45:45
    Key62=65506:0
    Key63=65450:42
    Key64=65513:0
    Key65=32:32
    Key66=65509:0
    Key67=65470:0
    Key68=65471:0
    Key69=65472:0
    Key70=65473:0
    Key71=65474:0
    Key72=65475:0
    Key73=65476:0
    Key74=65477:0
    Key75=65478:0
    Key76=65479:0
    Key77=65407:0
    Key78=65300:0
    Key79=65429:0
    Key80=65431:0
    Key81=65434:0
    Key82=65453:45
    Key83=65430:0
    Key84=65437:0
    Key85=65432:0
    Key86=65451:43
    Key87=65436:0
    Key88=65433:0
    Key89=65435:0
    Key90=65438:0
    Key91=65439:0
    Key92=65027:0
    Key93=0:0
    Key94=60:60
    Key95=65480:0
    Key96=65481:0
    Key97=0:0
    Key98=65318:0
    Key99=65317:0
    Key100=65315:0
    Key101=65319:0
    Key102=65314:0
    Key103=0:0
    Key104=65421:13
    Key105=65508:0
    Key106=65455:47
    Key107=65377:0
    Key108=65027:0
    Key109=65290:10
    Key110=65360:0
    Key111=65362:0
    Key112=65365:0
    Key113=65361:0
    Key114=65363:0
    Key115=65367:0
    Key116=65364:0
    Key117=65366:0
    Key118=65379:0
    Key119=65535:127
    Key120=0:0
    Key121=269025042:0
    Key122=269025041:0
    Key123=269025043:0
    Key124=269025066:0
    Key125=65469:61
    Key126=177:177
    Key127=65299:0
    Key128=269025098:0
    Key129=65454:46
    Key130=65329:0
    Key131=65332:0
    Key132=0:0
    Key133=65515:0
    Key134=65516:0
    Key135=65383:0
    Key136=65385:0
    Key137=65382:0

    [shiftcapslock]
    Key8=0:0
    Key9=65307:27
    Key10=33:33
    Key11=34:34
    Key12=35:35
    Key13=36:36
    Key14=37:37
    Key15=38:38
    Key16=47:47
    Key17=40:40
    Key18=41:41
    Key19=61:61
    Key20=63:63
    Key21=187:187
    Key22=65288:8
    Key23=65056:0
    Key24=113:113
    Key25=119:119
    Key26=101:101
    Key27=114:114
    Key28=116:116
    Key29=121:121
    Key30=117:117
    Key31=105:105
    Key32=111:111
    Key33=112:112
    Key34=42:42
    Key35=65104:96
    Key36=65293:13
    Key37=65507:0
    Key38=97:97
    Key39=115:115
    Key40=100:100
    Key41=102:102
    Key42=103:103
    Key43=104:104
    Key44=106:106
    Key45=107:107
    Key46=108:108
    Key47=231:231
    Key48=170:170
    Key49=124:124
    Key50=65505:0
    Key51=65106:94
    Key52=122:122
    Key53=120:120
    Key54=99:99
    Key55=118:118
    Key56=98:98
    Key57=110:110
    Key58=109:109
    Key59=59:59
    Key60=58:58
    Key61=95:95
    Key62=65506:0
    Key63=65450:42
    Key64=65511:0
    Key65=32:32
    Key66=65509:0
    Key67=65470:0
    Key68=65471:0
    Key69=65472:0
    Key70=65473:0
    Key71=65474:0
    Key72=65475:0
    Key73=65476:0
    Key74=65477:0
    Key75=65478:0
    Key76=65479:0
    Key77=65407:0
    Key78=65300:0
    Key79=65463:55
    Key80=65464:56
    Key81=65465:57
    Key82=65453:45
    Key83=65460:52
    Key84=65461:53
    Key85=65462:54
    Key86=65451:43
    Key87=65457:49
    Key88=65458:50
    Key89=65459:51
    Key90=65456:48
    Key91=65454:46
    Key92=65027:0
    Key93=0:0
    Key94=62:62
    Key95=65480:0
    Key96=65481:0
    Key97=0:0
    Key98=65318:0
    Key99=65317:0
    Key100=65315:0
    Key101=65319:0
    Key102=65314:0
    Key103=0:0
    Key104=65421:13
    Key105=65508:0
    Key106=65455:47
    Key107=65377:0
    Key108=65027:0
    Key109=65290:10
    Key110=65360:0
    Key111=65362:0
    Key112=65365:0
    Key113=65361:0
    Key114=65363:0
    Key115=65367:0
    Key116=65364:0
    Key117=65366:0
    Key118=65379:0
    Key119=65535:127
    Key120=0:0
    Key121=269025042:0
    Key122=269025041:0
    Key123=269025043:0
    Key124=269025066:0
    Key125=65469:61
    Key126=177:177
    Key127=65299:0
    Key128=269025098:0
    Key129=65454:46
    Key130=65329:0
    Key131=65332:0
    Key132=0:0
    Key133=65515:0
    Key134=65516:0
    Key135=65383:0
    Key136=65385:0
    Key137=65382:0

Leave a Reply