远程控制上的 Windows 媒体按钮在 WPF 中不起作用

发布于 2024-11-27 02:50:55 字数 1753 浏览 2 评论 0原文

我有一个指向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文