I don't have a Media Center Remote to test with, but from what I can find...
Pressing buttons on the MC remote will result in one of three types messages being sent to your application: WM_APPCOMMAND, WM_KEYDOWN or WM_INPUT. The first two are fairly simple - just synthetic keyboard interactions. The third is the difficult one.
First, you need to call RegisterRawInputDevices
with an array of RAWINPUTDEVICE
structures that indicate the data your application is interested in. In this case you'll need at least Page 0x000C Collection 0x01 and Page 0xFFBC Collection 0x88 to get the majority of the buttons. If you want to handle the Standyby button you also need Page 0x0001 Collection 0x80.
After that call you will get WM_INPUT messages for each button. This is as far as I can go at the moment, since I haven't found a decent explanation of the content of the HIDRAW structure beyond the fact that it can contain data for multiple events. I'd suggest dumping it out and seeing if you can locate the appropriate codes - from the Button Usage ID column.
Edit: processing the messages
In order to process the WM_APPCOMMAND messages you'll need to override the WndProc
method of your form:
// Some of the named constants:
const int WM_APPCOMMAND = 0x0319;
const int APPCOMMAND_BROWSER_BACK = 1;
const int APPCOMMAND_MEDIA_CHANNEL_DOWN = 52;
const int APPCOMMAND_MEDIA_CHANNEL_UP = 51;
const int APPCOMMAND_MEDIA_FAST_FORWARD = 49;
const int APPCOMMAND_VOLUME_MUTE = 8;
const int APPCOMMAND_MEDIA_PAUSE = 14;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_APPCOMMAND)
{
int lParam = unchecked ((int)m.LParam);
int cmd = unchecked ((short)((uint)lParam>>16));
switch (cmd)
{
case APPCOMMAND_BROWSER_BACK:
// process 'back' button
break;
case APPCOMMAND_MEDIA_CHANNEL_DOWN:
// process 'channel down' command
break;
}
}
base.WndProc(ref m);
}
There are more, but that's the gist of it. You'll need to find the values for the various named constants.