Using Remote Control Input Outside of Windows Media Center C#

孤街浪徒 提交于 2020-01-06 14:42:06

问题


I would like to make a very simple C# windows form application (or WPF) that can be controlled by the Media Center Remote Control that came with the computer. It's a very simple app that has an event listener that receives messages from the remote and calls the appropriate function. I found this article that explains how to do it yet I was not able to follow up: http://msdn.microsoft.com/en-us/library/windows/desktop/bb417079.aspx I've read the article many times yet I have no clue how execute it. I'm novice when it comes to HID programing, so please try to be as clear and detailed as possible. A full example would be appreciated. Thank You

Thank You Corey your answer was very helpfull, I mixed it with another code I found: http://discuss.mediacentersandbox.com/forums/thread/8549.aspx and it worked


回答1:


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.



来源:https://stackoverflow.com/questions/23461480/using-remote-control-input-outside-of-windows-media-center-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!