XBMC will be renamed to Kodi for v14. Read here for more details

HOW-TO:Modify keyboard.xml

From Kodi
Jump to: navigation, search
Home icon grey.png   ▶ Remote controls ▶ HOW-TO:Modify keyboard.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 where the file should be located after creation is in userdata

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.


Contents

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.

User keymaps are only processed when XBMC starts up, therfore you must restart XBMC to see any changes.

2 Where to find keyboard.xml

Keymap configuration files are stored in the "keymaps" folder in the userdata folder:


Future Helix feature: In the upcoming Kodi v14 the xbmc directories will be renamed to kodi.

Operative system File path
Android (see note) Android/data/org.xbmc.xbmc/files/.xbmc/userdata/
iOS /private/var/mobile/Library/Preferences/XBMC/userdata/
Linux ~/.xbmc/userdata/
Mac OS X (see note) /Users/<your_user_name>/Library/Application Support/XBMC/userdata/
OpenELEC /storage/.xbmc/userdata/
Windows Start - type %APPDATA%\XBMC\userdata - press <Enter>


2.1 Android location

Sometimes the exact path will differ from device to device. The Android userdata folder is usually inside of "sdcard" so the path might be /sdcard/Android/data/org.xbmc.xbmc/files/.xbmc/userdata/


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++. In Windows there is a third party keymap editor available from http://xbmcmce.sourceforge.net/, or this editor is also available through the Add-on:MCERemote add-on.

Windows

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  Win+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 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".

Linux

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:

<keymap>
  <global>
    <keyboard>
      ... key mappings here
    </keyboard>
  </global>
  <Home>
    <keyboard>
      ... key mappings here
    </keyboard>
  </Home>
  ... and so on
</keymap>

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 OSD (On Screen Display). So lets start by defining a global mapping for control+G to display Info:

<keymap>
  <global>
    <keyboard>
      <g mod="ctrl">Info</g>
    </keyboard>
  </global>
</keymap>

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:

<keymap>
  <global>
    <keyboard>
      <g mod="ctrl">Info</g>
    </keyboard>
  </global>
  <FullScreenVideo>
    <keyboard>
      <g mod="ctrl">OSD</g>
    </keyboard>
  </FullScreenVideo>
</keymap>

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>

as

<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 https://github.com/xbmc/xbmc/blob/master/xbmc/input/ButtonTranslator.cpp

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: The  Shift modifier can't be used alone. This is because XBMC isn't case sensitive when processing keystrokes, i.e. a gis the same as a G.
Personal tools
Namespaces

Variants
Actions
Navigation
Wiki help
Toolbox