|Remote controls||Keymaps||HOW-TO:Modify keymaps|
|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 Kodi reacts to keypresses, that is it determines what action is mapped to what keypress. There are two main reasons for modifying keyboard.xml:
- You want to change the standard key mappings because of a personal preference
- 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 keymaps, while the remainder of this article is focussed on the gory details of editing it.
All the keypresses that Kodi 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 Kodi 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 Kodi 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 Kodi. 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 Kodi starts up, therfore you must restart Kodi to see any changes.
2 Where to find keyboard.xml
Keymap configuration files are stored in the "keymaps" folder in the userdata folder:
|Operating system||File path|
|Android||Android/data/org.xbmc.kodi/files/.kodi/userdata/ (see note)|
|Mac||/Users/<your_user_name>/Library/Application Support/Kodi/userdata/ (see note)|
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.kodi/files/.kodi/userdata/
2.2 Microsoft Store version
Kodi installed from the Microsoft Store puts user data in %LOCALAPPDATA%\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalCache\Roaming\Kodi\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.
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:
- 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 http://xbmcmce.sourceforge.net/ 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.
Use your favourite text editor e.g. gedit. Remember that the .kodi 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 keymaps.
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 Kodi unless they are overridden by a mapping in another section. The <Home> section defines key mappings that apply only when you're at the Kodi 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:
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.
<d mod="longpress">Notification(Keypress, You kept pressing D!, 3)</d>
configures a long D keypress to execute the action.
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, 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 Kodi 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.
It's easy to make mistakes when writing a keyboard.xml file, and if Kodi 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 Kodi then start it and close it again. Now look in %APPDATA%\Kodi and you'll find a file called kodi.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:
that is I missed the "g" in </g>. If I run Kodi and then look at kodi.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 Kodi 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.
The ultimate reference for the possible keynames and actions is the Kodi 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 five key modifiers you can use in key mappings:
- ctrl or control
- ⇧ Shift
- ⊞ Win or super (the Windows key)
- longpress (holding down the key)