远程控制上的 Windows 媒体按钮在 WPF 中不起作用
我有一个指向 PC/TV 的遥控器,
键盘上的 CTRL + P 可以在应用程序中工作并播放/暂停。
遥控器可以在媒体播放器中播放/暂停,但在 WPF 应用程序中不起作用。
public MainWindow()
{
InitializeComponent();
ModifierKeys mk = ((ModifierKeys)(ModifierKeys.Control | ModifierKeys.Shift));
MyPlayPause.InputGestures.Add(new KeyGesture(Key.P, ModifierKeys.Control));
MyStop.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
MyRewind.InputGestures.Add(new KeyGesture(Key.B,mk));
MyFastForward.InputGestures.Add(new KeyGesture(Key.F,mk));
}
我的 XAML
<Window.CommandBindings>
<CommandBinding Command="{x:Static RemoteControlTest:MainWindow.MyPlayPause}" Executed="MyPlayPauseEvent"/>
<CommandBinding Command="{x:Static RemoteControlTest:MainWindow.MyStop}" Executed="MyStopEvent"/>
<CommandBinding Command="{x:Static RemoteControlTest:MainWindow.MyFastForward}" Executed="MyFastForwardEvent" />
<CommandBinding Command="{x:Static RemoteControlTest:MainWindow.MyRewind}" Executed="MyRewindEvent" />
</Window.CommandBindings>
事件适用于倒带和快进,但不适用于播放/暂停和停止。
我尝试下载 Media Glass http://mediaglass.codeplex.com/ ,这在遥控器上也有同样的问题当按 CTRL + P 时,
我发现通过应用以下内容,
System.Windows.Input.Key wpfLeftKey = Key.LeftCtrl;
var formsKey = (Forms.Keys)KeyInterop.VirtualKeyFromKey(wpfLeftKey);
我从输出中得到不同的结果
Windows 32 = LControlKey
WPF = LeftControl
我的想法是遥控器被编程为发送 LControlKey
因此,我需要做的是在 Win32 应用程序记录 LControlKey 时引发一个事件并强制事件触发。任何建议。 (在 InitiliseComponent() 之后?
我可能完全不走寻常路,或者可能是对的。???
I have a remote control pointing at the PC / TV
CTRL + P on the keyboard works and Plays / Pauses within the application.
The remote control can Play / Pause in Media Player but it doesnt work in a WPF app.
public MainWindow()
{
InitializeComponent();
ModifierKeys mk = ((ModifierKeys)(ModifierKeys.Control | ModifierKeys.Shift));
MyPlayPause.InputGestures.Add(new KeyGesture(Key.P, ModifierKeys.Control));
MyStop.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
MyRewind.InputGestures.Add(new KeyGesture(Key.B,mk));
MyFastForward.InputGestures.Add(new KeyGesture(Key.F,mk));
}
My XAML is
<Window.CommandBindings>
<CommandBinding Command="{x:Static RemoteControlTest:MainWindow.MyPlayPause}" Executed="MyPlayPauseEvent"/>
<CommandBinding Command="{x:Static RemoteControlTest:MainWindow.MyStop}" Executed="MyStopEvent"/>
<CommandBinding Command="{x:Static RemoteControlTest:MainWindow.MyFastForward}" Executed="MyFastForwardEvent" />
<CommandBinding Command="{x:Static RemoteControlTest:MainWindow.MyRewind}" Executed="MyRewindEvent" />
</Window.CommandBindings>
The events work for rewind and fast forward, but not for Play/Pause and Stop.
I tried downloading Media Glass http://mediaglass.codeplex.com/ and this has the same issue on the remote when pressing CTRL + P
I have found out that by applying the following
System.Windows.Input.Key wpfLeftKey = Key.LeftCtrl;
var formsKey = (Forms.Keys)KeyInterop.VirtualKeyFromKey(wpfLeftKey);
I get different results from my output
Windows 32 = LControlKey
WPF = LeftControl
My thinking is that the remote control is programmed to send out LControlKey
Therefore what I need to do is raise an event when the Win32 app records LControlKey and force the event to fire. Any suggestions. (After InitiliseComponent()?
I could be completey of the beaten track here, or could be right. ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看按键绑定
Check out Key Bindings