2011-08-01 49 views
0

我有一个遥控器,在应用中的键盘作品和播放/暂停在PC/TVWindows媒体按钮不工作在WPF

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> 

事件倒带的工作和快进,而不是播放/暂停和停止。

我尝试下载媒体玻璃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()?

我可以completey这里因循守旧的,或者可能是正确的???。

回答

1

退房Key Bindings

+0

伊夫添加,我得到的错误'找不到'System.Windows.Input.InputBinding'类型的匹配构造函数,你可以使用Arguments或FactoryMethod指令构造这种类型'行号'14'和行位置'10'。 –

+0

我添加了它做同样的事情:( –

+0

它工作时,我添加媒体密钥绑定MyPlayPause.InputGestures.Add(新的KeyGesture(Key.MediaPlayPause));因为遥控器正在发送不同的命令 –