Using keySend in Windows Media Center

Hey, I'm using C # to try and send key commands to Windows Media Center in Windows 7.

Currently, I can send keys such as 4 and see number 4 in the Windows Media Center.

The problem is any key combination like Ctrl + p (to pause the movie) does not seem to have any effect on the media center.

Any help would be greatly appreciated. Here is my code snippet.

    // 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;
    }
+3
source share
2 answers

I really was able to finally find a solution that worked on this website:

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

VK Class Remote Sender . Windows , /, .

! .

0

VK Class. MediaCenter 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.

+1

Source: https://habr.com/ru/post/1766516/


All Articles