Using the Remote Control Device with Windows

Microsoft Corporation

September 2002

Applies to:
    Microsoft® Windows® XP
    Microsoft Windows XP Media Center Edition

Summary: Learn about the infrared remote control system supported by some Microsoft operating systems and how applications can retrieve input from the remote control device. (11 printed pages)

Contents

Introduction
Infrared Input System
Remote Control Buttons
Retrieving Infrared Commands
Handling the Play and Pause Commands
For More Information

Introduction

Beginning with Microsoft® Windows® XP Service Pack 1, the Microsoft Windows XP Professional Edition and Microsoft Windows XP Media Center Edition operating systems will support input from an infrared remote control device. This device enhances the personal computer's capability to become part of a home entertainment system.

This article provides information about how this remote control system can be used by software developers. It contains the following topics:

  • Infrared Input System. Describes the remote control device and its connection to the computer.
  • Remote Control Buttons. Describes the standard and optional buttons on the remote control.
  • Retrieving Infrared Commands. Describes how an application retrieves commands from the remote control, and which commands are associated with the remote control buttons.
  • Handling the Play and Pause Commands. Describes how to handle commands from the Play and Pause buttons on the remote control in combination with Play/Pause commands from the keyboard.
  • For More Information. Gives sources of related information.

Infrared Input System

The following illustration shows a remote control designed for use with a Media Center PC.

Figure 1. Remote control device image

Figure 1. Remote control device

The appearance of the remote control may vary from manufacturer to manufacturer. However, the core functionality is constant.

The remote control interacts with an infrared sensor, which consists of the following hardware:

  • A receiver component that processes input from the remote control
  • A circuit for learning infrared commands
  • A universal serial bus (USB) connection that sends input notifications to software running on the computer
  • Two emitter ports

In addition, the sensor requires a device driver that supports the Plug and Play specification. A default driver is installed with the versions of the Microsoft Windows operating system that support the infrared sensor.

The USB cable enables users to place the sensor near the monitor so they can point the remote at the monitor when sending commands to the computer. Alternatively, the sensor might be mounted in the front panel of the computer by the manufacturer.

Input from the remote control is processed as follows:

  1. The sensor receives the signal and forwards it to a device driver on the computer.
  2. The device driver converts the input into a WM_INPUT, WM_APPCOMMAND, WM_KEYDOWN, WM_KEYPRESS, or WM_KEYUP message.
  3. Windows places these messages in the message queue to be processed by a program's main window procedure.
  4. The foreground program processes messages of interest. For example, a digital media streaming program could process the messages corresponding to the transport buttons (Pause, Play, Stop, Fast Forward, and Rewind) but ignore messages from the numeric keypad.

Remote Control Buttons

Remote control design may vary by manufacturer. However, all devices are required to have a set of standard buttons that fall into four categories.

Navigation buttons:

  • eHome
  • Up
  • Down
  • Left
  • Right
  • OK
  • Back
  • Details
  • Guide
  • TV/Jump

Transport buttons:

  • Play
  • Pause
  • Stop
  • Record
  • Fast Forward
  • Rewind
  • Skip
  • Replay

AV and Power Control buttons:

  • Volume +
  • Volume -
  • Chan/Page +
  • Chan/Page -
  • Mute
  • DVD Menu
  • Standby

Data Entry buttons:

  • 0
  • 1
  • 2 ABC
  • 3 DEF
  • 4 GHI
  • 5 JKL
  • 6 MNO
  • 7 PQRS
  • 8 TUV
  • 9 WXYZ
  • Clear
  • Enter

In addition to the required buttons, a manufacturer may incorporate the following optional buttons, which are divided into four categories. Applications should not rely on the presence of these buttons.

Shortcut buttons:

  • My TV
  • My Music
  • Recorded TV
  • My Pictures
  • My Videos

DVD buttons:

  • DVD Angle
  • DVD Audio
  • DVD Subtitle

Keypad buttons:

  • #
  • *

OEM-specific buttons:

  • OEM 1
  • OEM 2

Retrieving Infrared Commands

This section describes the Windows commands generated by the remote control device driver and how to retrieve them so that your application can respond appropriately to input.

The following table shows the associated messages and keyboard equivalents for the compulsory and optional buttons on the remote control.

Button Message Command Keyboard equivalent
# To be determined SHIFT+3
* To be determined SHIFT+8
Back WM_APPCOMMAND APPCOMMAND_BROWSER_BACK BACKSPACE
Chan/Page Down WM_APPCOMMAND APPCOMMAND_MEDIA_CHANNEL_DOWN MINUS SIGN (-)

CTRL+MINUS SIGN

PAGE DOWN

Chan/Page Up WM_APPCOMMAND APPCOMMAND_MEDIA_CHANNEL_UP PLUS SIGN (+) CTRL+SHIFT+PLUS SIGN

PAGE UP

Clear WM_KEYDOWN VK_ESCAPE ESC
Details WM_INPUT
Down WM_KEYDOWN VK_DOWN DOWN ARROW
DVD Angle WM_INPUT
DVD Audio WM_INPUT
DVD Menu WM_INPUT
DVD Subtitle WM_INPUT
eHome Not for use by applications.
Enter VK_RETURN ENTER
Fwd WM_APPCOMMAND APPCOMMAND_MEDIA_FASTFORWARD CTRL+SHIFT+F
Guide WM_INPUT
Left WM_KEYDOWN VK_LEFT LEFT ARROW
Mute WM_APPCOMMAND APPCOMMAND_VOLUME_MUTE F8
My Music WM_INPUT
My Pictures WM_INPUT
Recorded TV WM_INPUT
My TV WM_INPUT
My Videos WM_INPUT
Number keys WM_KEYDOWN VK_0 to VK_9 0 to 9
OEM1 WM_INPUT
OEM2 WM_INPUT
OK WM_KEYDOWN VK_RETURN ENTER

SPACEBAR

Pause WM_APPCOMMAND APPCOMMAND_MEDIA_PAUSE CTRL+P
Play WM_APPCOMMAND APPCOMMAND_MEDIA_PLAY CTRL+SHIFT+P
Record WM_APPCOMMAND APPCOMMAND_MEDIA_RECORD CTRL+R
Replay WM_APPCOMMAND APPCOMMAND_MEDIA_PREVIOUSTRACK CTRL+B
Rewind WM_APPCOMMAND APPCOMMAND_MEDIA_REWIND
Right WM_KEYDOWN VK_RIGHT RIGHT ARROW
Skip WM_APPCOMMAND APPCOMMAND_MEDIA_NEXTTRACK CTRL+F
Standby WM_INPUT
Stop WM_APPCOMMAND APPCOMMAND_MEDIA_STOP CTRL+S
Up WM_KEYDOWN VK_UP UP ARROW
TV/Jump WM_INPUT
Vol Down WM_APPCOMMAND APPCOMMAND_VOLUME_DOWN F9
Vol Up WM_APPCOMMAND APPCOMMAND_VOLUME_UP F10

Buttons that generate WM_INPUT messages are defined according to the Human Interface Device (HID) specification. The following table shows the HID mapping of these buttons.

Button Usage page Page name Collection
usage ID
Button
usage ID
Details 0x0C Consumer controls 0x01 0x209 (AC properties)
DVD Angle 0xFFBC Vendor-defined 0x88 0x4B
DVD Audio 0xFFBC Vendor-defined 0x88 0x4C
DVD Menu 0xFFBC Vendor-defined 0x88 0x24
DVD Subtitle 0xFFBC Vendor-defined 0x88 0x4D
Guide 0x0C Consumer controls 0x01 0x8D (AC Program Guide)
My Music 0xFFBC Vendor-defined 0x88 0x47
My Pictures 0xFFBC Vendor-defined 0x88 0x49
My TV 0xFFBC Vendor-defined 0x88 0x46
My Videos 0xFFBC Vendor-defined 0x88 0x4A
OEM1 0xFFBC Vendor-defined 0x88 0x80
OEM2 0xFFBC Vendor-defined 0x88 0x81
Recorded TV 0xFFBC Vendor-defined 0x88 0x48
Standby 0x01 Generic desktop 0x80 0x82
TV/Jump 0xFFBC Vendor-defined 0x88 0x25

In order to process WM_INPUT messages, the application must first register the devices from which it receives data. You can do this by using the Win32® function RegisterRawInputDevices. Each RAWINPUTDEVICE structure passed to this function specifies one usage page and usage.

The following example C++ code registers the device to receive input from the controls defined on the vendor-defined usage page that have a usage of 0x88:

RAWINPUTDEVICE Rid[1];

Rid[0].usUsagePage = 0xFFBC;
Rid[0].usUsage = 0x88; 
Rid[0].dwFlags = 0;

if (RegisterRawInputDevices(Rid, 1, sizeof(Rid[0])) == FALSE) 
{
    ErrorExit();  // Add error-handling code here.
}

To identify the event that triggered a WM_INPUT message, your application must parse the data passed to the window procedure as the lParam parameter.

If you are using the Microsoft .NET Framework, you must implement the WndProc method to retrieve messages. The WndProc method is a member of the NativeWindow class found in the System.Windows.Forms namespace. The overridden method is called each time a new message is placed in the form's message queue. Before returning, the method must call the base WndProc method to ensure that unprocessed messages are handled properly.

The following C# code shows how to use the WndProc method to retrieve WM_KEYDOWN messages:

using System.Windows.Forms;
.
.
.
class Form1Window : NativeWindow
{ 
  private const int WM_KEYDOWN = 0x0100;
  private int iChar;
  public Form1 form;
 
  protected override void WndProc(ref Message message)
  {
    // Handle the navigation and numeric buttons.
 
    if (message.Msg == WM_KEYDOWN)
    {
      iChar = message.WParam.ToInt32();
 
      switch(iChar)
      {
        case (int)Keys.D0:
          // Handle 0 key here.  
          break;
       // Insert more cases here.
.
.
.
      }  // End switch.
    }    // End key messages.
    base.WndProc(ref message);
  }      // End WndProc
}        // End class.

In the initialization code for the main form, you must create an instance of the Form1Window class and assign the main form to it, as follows:

public Form1()
{
  InitializeComponent();
  Form1Window win = new Form1Window();
  win.form = this;
  win.AssignHandle(this.Handle);
} 

Handling the Play and Pause Commands

The Play and Pause buttons on the remote control generate separate commands, APPCOMMAND_MEDIA_PLAY and APPCOMMAND_MEDIA_PAUSE, respectively. In addition, some keyboards use a single button to switch between the playing and paused states, generating an APPCOMMAND_MEDIA_PLAY_PAUSE message. Applications should be able to process messages from either the remote control or the keyboard, while keeping track of the current playback state and responding appropriately.

The following table shows the playback state, the keyboard or remote control command, and the recommended action an application should take in response to these messages.

State Command Action
Stopped APPCOMMAND_MEDIA_PLAY Play
Stopped APPCOMMAND_MEDIA_PAUSE Nothing
Stopped APPCOMMAND_MEDIA_PLAY_PAUSE Play
Playing APPCOMMAND_MEDIA_PLAY Nothing
Playing APPCOMMAND_MEDIA_PAUSE Pause
Playing APPCOMMAND_MEDIA_PLAY_PAUSE Pause
Paused APPCOMMAND_MEDIA_PLAY Play
Paused APPCOMMAND_MEDIA_PAUSE Nothing
Paused APPCOMMAND_MEDIA_PLAY_PAUSE Play

For More Information

To learn more about Human Interface Device (HID) and the structure of HID data, see the USB home page (https://www.usb.org).

To learn more about how to retrieve HID data from a WM_INPUT message, see the Raw Input page at MSDN.