将 keySend 与 Windows Media Center 结合使用
嘿,我正在使用 C# 尝试在 Windows 7 中向 Windows Media Center 发送按键命令。
目前我可以发送像 4 这样的按键,并看到数字 4 出现在 Windows Media Center 上。
问题是像 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;
}
Hey, I am using C# to try to send key commands to windows media center in windows 7.
Currently I can send keys like 4 and see the number 4 appears on the windows media center.
The problem is any key combination like Ctrl+p (to pause a movie) does not seem to have any effects 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,我无法通过 VK 课程取得任何有用的成果。 MediaCenter 不会响应此 keydown/keyup 内容。
相反,我使用此方法将媒体中心置于前面:
之后,SendKeys 应该可以工作。我只是把它包裹在 try/catch 上。
现在,
SendKey("{ENTER}");
以及SendKey("{RIGHT}");
和所有其他键在 Windows 7 上都可以正常工作。I actually wasn't able to achieve anything usefull with the VK Class. MediaCenter wouldn't respond to this keydown/keyup stuff.
Instead I used this method to bring the media center to front:
Afterwards, SendKeys should work. I just wrapped it around try/catch.
Now
SendKey("{ENTER}");
as well asSendKey("{RIGHT}");
and all other keys works just fine on Windows 7.我实际上终于找到了适用于该网站的解决方案:
http://michbex.com/wordpress /?p=3
我最终使用他的 VK 类和远程发送器类方法来解决这个问题。 Windows 媒体中心必须具有较低级别的键挂钩,并且您必须实现 keyup/keydown 发送解决方案才能利用这些挂钩。
我终于可以暂停看电影了!我将清理代码并稍后发布。
I was actually able to finally find a solution that worked on this website:
http://michbex.com/wordpress/?p=3
I ended up using his VK Class and Remote Sender Class methods to solve this problem. Windows media center must have lower level key hooks and you must implement a keyup/keydown sending solution to exploited the hooks.
I can finally pause a movie! I will clean up the code and post it later.