在Windows Media Center C#外部使用远程控制输入 [英] Using Remote Control Input Outside of Windows Media Center C#

查看:303
本文介绍了在Windows Media Center C#外部使用远程控制输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个非常简单的C#Windows窗体应用程序(或WPF),可以由计算机随附的Media Center远程控制来控制. 这是一个非常简单的应用程序,具有事件侦听器,该事件侦听器从远程接收消息并调用适当的功能. 我发现这篇文章解释了如何执行此操作,但仍无法跟进: http://msdn.microsoft.com/en-us/library/windows/desktop/bb417079.aspx 我已经阅读了很多次文章,但是我不知道如何执行. 关于HID编程,我是新手, 因此,请尝试尽可能清楚和详细. 一个完整的例子将不胜感激. 谢谢

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

谢谢您,Corey,您的回答非常有帮助,我将其与发现的另一个代码混合在一起: http://discuss.mediacentersandbox.com/forums/thread/8549.aspx 而且有效

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

推荐答案

我没有Media Center Remote可以测试,但是从我可以找到的地方...

I don't have a Media Center Remote to test with, but from what I can find...

按下MC遥控器上的按钮将导致以下三种类型的消息之一发送到您的应用程序:WM_APPCOMMAND,WM_KEYDOWN或WM_INPUT.前两个非常简单-只是合成键盘交互.第三是困难的.

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.

首先,您需要调用 RegisterRawInputDevices 包含RAWINPUTDEVICE结构的数组,这些结构指示您的应用程序感兴趣的数据.在这种情况下,您至少需要Page 0x000C Collection 0x01和Page 0xFFBC Collection 0x88才能获取大多数按钮.如果要处理待机"按钮,则还需要页面0x0001集合0x80".

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.

该呼叫之后,您将为每个按钮获得WM_INPUT消息.目前为止,这是我可以做的,因为除了HIDRAW结构可以包含多个事件的数据以外,还没有找到关于HIDRAW结构的合理解释.我建议将其转储出去,看看是否可以在按钮用法ID"列中找到合适的代码.

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.

处理消息

要处理WM_APPCOMMAND消息,您需要覆盖表单的WndProc方法:

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.

这篇关于在Windows Media Center C#外部使用远程控制输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆