pandap / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

RawInput does not work for WPF applications #785

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
RawInput relies on an application using WinForms. In Device.RegisterDevice, 
rawinput/DeviceRI.cpp, line 64,

Application::AddMessageFilter( filter );

will allow RawInput to capture messages for a WinForms app, but the statement 
is useless for a WPF app. To get the same behavior in WPF, you would add a 
handler to System.Windows.Interop.ComponentDispatcher.ThreadFilterMessage.

Attached is a small program to test this. Using the commented 
Device.RegisterDevice lines 46-7 in MainWindow.xaml.cs, no message boxes 
appear. But using my bypassRegisterDevice and addThreadFilter functions makes 
message boxes appear any time a keyboard or mouse event is received.

I believe the best solution would be to remove lines 61-65 in DeviceRI.cpp, and 
make OnWmInput public so that it would be up to the developer to set up their 
message filter, making RawInput framework agnostic. Right now OnWmInput is 
internal, so I had to use reflection to test this out, which is not an ideal 
workaround.

An alternative solution would be to provide an overload to 
Device.RegisterDevice which instead of calling Application::AddMessageFilter, 
would call my addThreadFilter.

Original issue reported on code.google.com by plaf...@gmail.com on 19 Mar 2011 at 2:35

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by Mike.Popoloski on 28 May 2011 at 12:00

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r2085.

Original comment by Mike.Popoloski on 14 Jun 2011 at 3:46

GoogleCodeExporter commented 9 years ago
I added an additional constructor that allows you to disable the default thread 
filter, and made a HandleMessage function that you can use to invoke OnWmInput.

Original comment by Mike.Popoloski on 14 Jun 2011 at 3:47