嗨,我使用C#,试图键命令发送到Windows媒体中心在视窗7。

目前我可以发送键,如图4和显示的数字上的Windows Media中心4次出现。

问题是如Ctrl + P的任意键的组合(暂停电影)似乎不具有媒体中心上的任何影响。

任何帮助,将不胜感激。这是我的代码片段。

    // Get a handle to an application window.
    [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(string lpClassName,
    string lpWindowName);

    // Activate an application window.
    [DllImport("USER32.DLL")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);


    String HandleClass = "eHome Render Window";
    String HandleWindow = "Windows Media Center";

    private bool SendKeyCommand()
    {
        bool success = true;
        IntPtr PrgHandle = FindWindow(HandleClass, HandleWindow);
        if (PrgHandle == IntPtr.Zero)
        {
            MessageBox.Show(HandleWindow + " is not running");
            return false;
        }
        SetForegroundWindow(PrgHandle);
        SendKeys.SendWait("^p");
        return success;
    }
有帮助吗?

解决方案 2

我居然能终于发现本网站上工作的解决方案:

http://michbex.com/wordpress/?p=3

最后我用他的VK级和远程发送类的方法来解决这个问题。 Windows媒体中心必须具备较低的水平钥匙钩,你必须实现一个KEYUP /发送的keydown解决方案利用了钩。

我终于可以暂停电影!我将清理代码后再发布。

其他提示

其实,我没能实现与VK类的任何有用的。媒体中心不会对这个的keydown / KEYUP东西响应。

相反,我用这个方法使媒体中心到前:

[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);

public static void activateMediaCenterForm()
{
    System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("ehshell");
    if (p.Length > 0) //found
    {
        SetForegroundWindow(p[0].MainWindowHandle);
    }
    //else not Found -> Do nothing.
}

此后,的SendKeys应该工作。我只是裹住try / catch语句。

private void SendKey(string key)
{
    activateMediaCenterForm();
    try
    {
        SendKeys.SendWait(key);
    }
    catch (Exception e)
    {
        //Handle exception, if needed.
    }
}

现在SendKey("{ENTER}");以及SendKey("{RIGHT}");和所有其他键只是正常的Windows 7。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top