HOW-TO:Modify keymaps

From Official Kodi Wiki
Revision as of 08:30, 26 November 2012 by UNiversal (talk) (missing information I woulnd know about like e.g. where these files are in supported OS's)
Jump to: navigation, search

 Controls: Keyboard controls Remote controls RC reviews Keymap files Modifying keyboard.xml Custom keymaps lircmap.xml 

Cleanup.png This page or section may require cleanup, updating, spellchecking, reformatting and/or updated images. Please improve this page if you can. The discussion page may contain suggestions.

The keyboard.xml file controls how XBMC reacts to keypresses, that is it determines what action is mapped to what keypress. There are two main reasons for modifying keyboard.xml:

  1. You want to change the standard key mappings because of a personal preference
  2. You are configuring a Media Center remote control that sends keypresses

You can edit keyboard.xml using any text editor such as Notepad in Windows or gedit/nano in Linux. The location of the file is:

Android - ?

IOS - ?

Linux - $HOME/.xbmc/userdata/keymaps/keyboard.xml

OS X - ?

Windows - %APPDATA%\xbmc\userdata\keymaps\keyboard.xml

There is a more detailed discussion of the keyboard.xml file at Keyboard.xml, while the remainder of this article is focussed on the gory details of editing it.

1 Introduction

All the keypresses that XBMC responds to, for example "P" for "play" and "X" for "stop" are configured in a file called keyboard.xml. Actually there are two keyboard.xml files. There is the system keyboard.xml that contains all the standard key mappings, and each user optionally has their own userdata keyboard.xml that contains just their customised key mappings.

The userdata keyboard.xml only needs to contain additional key mappings, or key mappings that override the defaults in the system keyboard.xml. When XBMC is trying to decide how to respond to a keypress it first looks in the userdata keyboard.xml. If it doesn't find a mapping for the keypress XBMC then looks in the system keyboard.xml. This means that the userdata keyboard.xml is typically quite short because it only needs to define mappings for a few keys.

You can change key mappings by editing the system keyboard.xml, but we strongly recommend you don't do this. The system keyboard.xml is a big complicated file, and if you introduce an error into it you can break all the key mappings. Also any changes you make risk being overwritten if you upgrade XBMC. In general you should only ever edit your userdata keyboard.xml. Even if you make a horrendous hash of this you just need to delete or rename your userdata keyboard.xml to restore the default key mappings.

2 Where to find keyboard.xml


The userdata keyboard.xml is kept in %APPDATA%\xbmc\userdata\keymaps\keyboard.xml, where %APPDATA% is an environment variable that varies depending on what version of Windows you use. For example on my PC runnings Windows 7 my %APPDATA% is C:\Users\renniej\AppData\Roaming.

Note that %APPDATA% contains the username ("renniej" in my case). This means that if several different users are using the same PC each user has their own keyboard.xml so changes you make to one user won't affect the others. If you really really want your changes to affect all users you can either (carefully!) edit the system keyboard.xml or you can use portable mode.


The userdata keyboard.xml is kept in $HOME/.xbmc/userdata/keymaps/keyboard.xml, where once again $home is an enviroment variable. In most text editors like gedit the .xbmc directory won'tbe displayed and you need to enable displaying hidden files.

3 How to edit keyboard.xml

keyboard.xml is just a text file so you can edit it it using any text editor e.g. in Windows use Notepad. If you use Windows there is a third party keymap editor available from, or this editor is also available through the MCERemote add-on.


To use Notepad to edit your userdata keyboard.xml click Start then Run, or in Win7 click Start then All Programs then Accessories then Run, or press the keyboard shortcut Windows-R, then when the Run dialog opens type in:

notepad %APPDATA%\XBMC\userdata\keymaps\keyboard.xml

If you haven't edited your keyboard.xml before Notepad will ask "Do you want to create a new file?" and you should click Yes.

If you have downloaded the KeyMapEdit applet from run it then select File/Open and double click "keyboard.xml".

If you use the MCERemote add-on just select the "Edit keyboard.xml" option. Note that KeyMapEdit.exe isn't included in the MCERemote add-on by default (because the rules for add-ons prohibit including executable files). You need to go into the add-on settings Misc section and enable the setting "Update/install keymap editor" then select "Edit keyboard.xml".


Use your favourite text editor e.g. gedit. Remember that the .xbmc directory is hidden so you need to show hidden files to see it.

4 What to put in keyboard.xml

This is an outline rather than a definitive guide. For the full details see Keyboard.xml.

A keyboard.xml file will look something like:

      ... key mappings here
      ... key mappings here
  ... and so on

The keyboard.xml must start with <keymap> and end with </keymap>. In between are a number of sections; in the example above the first section is <global>, the second section is <Home>, and there can be lots of other sections as well.

The <global> section defines key mappings that apply everywhere in XBMC unless they are overridden by a mapping in another section. The <Home> section defines key mappings that apply only when you're at the XBMC home screen. Other sections define mappings that apply to other screens, for example the <FullScreenVideo> section defines mappings that apply when you're watching a video full screen. The easiest way to get a list of all the section names is to open the system keyboard.xml in Notepad and look through it.

The key mappings have the form:

<keyname mod="modifiers">SomeAction</keyname>

As with the section names, to see possible key names look at the system keyboard.xml. In fact copying and pasting from the system keyboard.xml is probably the easiest way to construct your custom keyboard.xml.

You need only only include the mod="modifiers" if you want to combine the key with a keyboard modifer like control, shift or alt. For example:

<d>Notification(Keypress, You pressed D!, 3)</d>

configures the D key to execute the action Notification(Keypress, You pressed D!, 3) while:

<d mod="ctrl,alt">Notification(Keypress, You pressed ctrl-alt-D!, 3)</d>

configures a control-alt-D keypress to execute the action. Incidentally the Notification action displays a little message at the bottom right of the screen. This can be useful for testing your key mappings.

5 An example

This example is going to be a bit contrived, but after all it's only intended as an example of how you might make some more useful key mapping.

Media Center remote controls usually have a button labelled "Guide", and when you press it this button usually sends a control-G keystroke. In this example we'll configure the Guide button to display the Info screen except when playing a video, when we'll configure it to show the On Screen Display. So lets start by defining a global mapping for control-G to display Info:

      <g mod="ctrl">Info</g>

From the previous section it should be obvious what this key mapping does so I won't dwell on it further. If you create a userdata keyboard.xml with this mapping and run XBMC you should find that whenever you press control-G it displays the Info screen.

However this will make control-G display Info when playing a video, and we want it to display the OSD instead. To achieve this modify the keyboard.xml to:

      <g mod="ctrl">Info</g>
      <g mod="ctrl">OSD</g>

The global action for control-G is still Info, but the <FullScreenVideo> section overrides the global mapping when playing a video and configures control-G to display the OSD instead.

6 Debugging

It's easy to make mistakes when writing a keyboard.xml file, and if XBMC finds an error in your keyboard.xml it will simply stop processing it, leaving you wondering why your key mappings aren't working. To check for errors in your keyboard.xml turn debug logging on (in the Settings screen go into System then Debugging and enable the Enable debug logging option), then close XBMC then start it and close it again. Now look in %APPDATA%\XBMC and you'll find a file called xbmc.log. Open this file in Notepad and you should be able to find the error.

For example, take the keymapping above but suppose I mistype:

<g mod="ctrl">Info</g>


<g mod="ctrl">Info</>

that is I missed the "g" in </g>. If I run XBMC and then look at xbmc.log I find:

 INFO: Loading special://masterprofile/keymaps/keyboard.xml
ERROR: Error loading keymap: special://masterprofile/keymaps/keyboard.xml, Line 4
             Error reading end tag.

Finally, the Notification action can useful when you're testing your key mappings as it displays a little message at the bottom right of the screen to confirm XBMC has processed the keystroke. A typical example would be:

<g mod="ctrl">Notification(This is the title, This is the message, 3)</g>

and the last argument, 3, is the number of seconds to display the message.

7 Reference

The ultimate reference for the possible keynames and actions is the XBMC source code and in particular the source file ButtonTranslator.cpp, which you can find at

For the key names look for the function CButtonTranslator::TranslateKeyboardString.

For the actions look for "static const ActionMapping actions[]".

For the sections look for "static const ActionMapping windows[]".

Finally, there are four key modifiers you can use in key mappings:

  • ctrl or control
  • shift
  • alt
  • win or super (the Windows key)

Note that the shift modifier can't be used alone. This is because XBMC isn't case sensitive when processing keystrokes, i.e. a g keypress is the same as a G keypress.