Using a Microsoft remote control in Windows

This article applies to remote controls that use the Microsoft eHome device driver. If you are unsure whether your remote is an eHome remote look in the Device Manager under Human Interface Devices and see if there is a device called "Microsoft eHome Infrared Transceiver" or something similar.



The above example is from Windows 7. If the eHome device does not appear you aren't using the eHome driver and you should read no further. For MCE remotes see Using an MCE remote control in Windows and for general notes on remote controllers see Remote Controls.

Introduction
The simplest way to use an eHome remote with XBMC is to configure it to emulate a keyboard. The eHome driver can be configured by modifying the registry (details below). The details are rather involved, but there are various resources you can use that make it all very simple.

EliteGamer360 has written a registry config file and associated keyboard.xml and these are available from http://xbmccustomregis.sourceforge.net/.

jhsrennie has written an add-on to configure MS remotes. To install it run XBMC and go to Settings, Add-ons, Get Add-ons, XBMC.org Add-ons, Program Add-ons and select MCERemote. Once installed, you can open the add-on by selecting Programs from the home page then MCERemote. The addon includes an option to display the instructions.

Default eHome configuration
Any version of Windows from Windows XP onwards will automatically detect and install a Microsoft remote as soon as you connect it. With versions of XBMC from v10.0 Dharma onwards most of the buttons on the Microsoft remote will work immediately. The exceptions I know about are:

 The Info button; sometimes labelled More or just i. The volume buttons will control the Windows volume setting not the XBMC volume The four coloured buttons (not all MS remotes have these) won't do anything With Vista/Windows 7 the Live TV, Recorded TV and Guide buttons will start Windows Media Center. With Windows XP (non-Media Center Edition) these buttons won't do anything The Green/Windows button will start Windows Media Center 

For most people this will be fine, and in that case you don't need to do anything further. The only reason for continuing with this article is if you want to customise the Microsoft remote to change the actions of any of the buttons or to make the Info and coloured buttons work.

Useful resources
http://xbmcmce.sourceforge.net/ has various utilities to help with tweaking the button mapping. ShowKey will show you what keypresses or AppCommand messages are being sent, and KeyMapEdit is a utility for editing the keyboard.xml file.

The remainder of this article describes the gory details of configuring the Microsoft remote. This probably looks frighteningly complicated to most of us, but very few people need to read further as EliteGamer360's scripts and/or the MCERemote add-on should do everything you need. Only the curious and determined need read further.

How the MS remote works
The Microsoft remote, or more accurately the eHome device driver, keeps the button configuration in the registry value ReportMappingTable in the key:

HKEY_LOCAL_MACHINE \SYSTEM \CurrentControlSet \Services \HidIr \Remotes \745a17a0-74d3-11d0-b6fe-00a0c90f57da

This is a binary array consisting of rows of 7 bytes. Each row defines one button. The seven bytes in the row are:

Byte 4 determines what the eHome driver will do when the button is pressed. If byte 4 is set to 03 the eHome driver will generate a "Raw Input" message and if byte 4 is 04 this will cause the button to send a keypress i.e. Windows will react as if a key had been pressed on the keyboard. If byte 4 is 01 the eHome driver will either send either a multimedia keypress or an APPCOMMAND message.

Byte 4 = 03: Raw Input messages
If byte 4 is set to 03 the eHome driver will generate a "Raw Input" message, see http://msdn.microsoft.com/en-us/library/ms645536(v=vs.85).aspx. The only raw input messages likely to be useful are:

Byte 4 = 04: Normal keypresses
If byte 4 is set to 04 then byte 5 contains modifiers like control, shift, alt, etc and byte 6 contains the key code.

The value of byte 5, the key modifier, can be:

If you're happy with binary numbers you've probably spotted that bit 0 specifies Control, bit 1 specifies Shift, bit 2 specifies Alt and bit 3 specifies the Windows key.

The key code is not an ACSII code or a scan code. It's an arbitrary code selected by MS. You can find a list of the codes in http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf. The button numbers obey no obvious logic.

To give a specific example, suppose you want to configure the Play button to send the Media Center keyboard shortcut for "Play", the 7 bytes would be:

16,00,00,00,04,03,13

Byte 4 = 01: Multimedia key or APPCOMMAND message
The Microsoft Multimedia Keyboard and various clones have keys for functions like "Play" and "Stop". If byte 4 is set to 01 the eHome driver may generate a multimedia keyboard keypress. Alternatively, and with no onbvious logic, it may generate the Windows message WM_APPCOMMAND instead. The WM_APPCOMMAND message is used to send commands like "Play", 2Pause", "Stop", etc. See http://msdn.microsoft.com/en-us/library/ms647591(v=vs.85).aspx for details.

The multimedia keys have key codes that can be greater than 255 (0xFF) so they need two bytes to represnt them. Byte 5 is used for the low byte and byte 6 is used for the high byte, though in most cases the high byte will be zero. This means that there is no byte available to specify the key modifiers, so you cannot combine a multimedia keypress with ctrl, shift, alt, etc.

Following on from the example above, suppose you want to configure the Play button to send the Multimedia Play/Pause keypress i.e. Play then Pause the media on alternate presses. The 7 bytes would be:

16,00,00,00,01,cd,00

The key codes for the multimedia keys are also listed in http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf. They are the keys with the "HID usage page" set to 0C. The normal keys have the "HID usage page" set to 07.

Table of remote button codes
The following table lists all the known button numbers. Thanks to the many people who put effort into discovering these numbers.

Table of key codes
This data is taken from http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf. The data has been reproduced here just in case Microsoft ever remove the link to the tranlate.pdf file:

Multimedia keys
The following has been established by experiment. There is no guarantee that the behaviour will be the same on all platforms.

Windows normally responds to Multimedia keypresses by generating WM_APPCOMMAND messages, so for example the Stop command, 00B7, generates both a VK_MEDIA_STOP keypress and a WM_APPCOMMAND 13 - Stop message.