Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Commit 7a1149c

Browse files
committed
RawInputEventArgs (and thus also HidInputEventArgs, KeyboardInputEventArgs, and MouseInputEventArgs) now has a WindowHandle property that can be used to retrieve the handle of the window that received the raw input event.
1 parent c5a6efa commit 7a1149c

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

Source/SharpDX.RawInput/Device.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ public static void RegisterDevice(UsagePage usagePage, UsageId usageId, DeviceFl
141141
/// Handles a RawInput message manually.
142142
/// </summary>
143143
/// <param name="rawInputMessagePointer">A pointer to a RawInput message.</param>
144+
/// <param name="hwnd">The handle of the window that received the RawInput message.</param>
144145
/// <remarks>
145146
/// This method can be used directly when handling RawInput messages from non-WinForms application.
146147
/// </remarks>
147-
public static void HandleMessage(IntPtr rawInputMessagePointer)
148+
public static void HandleMessage(IntPtr rawInputMessagePointer, IntPtr hwnd)
148149
{
149150
unsafe
150151
{
@@ -165,15 +166,15 @@ public static void HandleMessage(IntPtr rawInputMessagePointer)
165166
{
166167
case DeviceType.HumanInputDevice:
167168
if (RawInput != null)
168-
RawInput(null, new HidInputEventArgs(ref *rawInput));
169+
RawInput(null, new HidInputEventArgs(ref *rawInput, hwnd));
169170
break;
170171
case DeviceType.Keyboard:
171172
if (KeyboardInput != null)
172-
KeyboardInput(null, new KeyboardInputEventArgs(ref *rawInput));
173+
KeyboardInput(null, new KeyboardInputEventArgs(ref *rawInput, hwnd));
173174
break;
174175
case DeviceType.Mouse:
175176
if (MouseInput != null)
176-
MouseInput(null, new MouseInputEventArgs(ref *rawInput));
177+
MouseInput(null, new MouseInputEventArgs(ref *rawInput, hwnd));
177178
break;
178179
}
179180
}
@@ -193,7 +194,7 @@ public virtual bool PreFilterMessage(ref Message m)
193194
{
194195
// Handle only WM_INPUT messages
195196
if (m.Msg == WmInput)
196-
HandleMessage(m.LParam);
197+
HandleMessage(m.LParam, m.HWnd);
197198
return false;
198199
}
199200
}

Source/SharpDX.RawInput/HidInputEventArgs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public HidInputEventArgs()
3838
/// Initializes a new instance of the <see cref="HidInputEventArgs"/> class.
3939
/// </summary>
4040
/// <param name="rawInput">The raw input.</param>
41-
internal HidInputEventArgs(ref RawInput rawInput) : base(ref rawInput)
41+
/// <param name="hwnd">The handle of the window that received the RawInput mesage.</param>
42+
internal HidInputEventArgs(ref RawInput rawInput, IntPtr hwnd) : base(ref rawInput, hwnd)
4243
{
4344
Count = rawInput.Data.Hid.Count;
4445
DataSize = rawInput.Data.Hid.SizeHid;

Source/SharpDX.RawInput/KeyboardInputEventArgs.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
// THE SOFTWARE.
20+
21+
using System;
2022
using System.Windows.Forms;
2123

2224
namespace SharpDX.RawInput
@@ -37,8 +39,9 @@ public KeyboardInputEventArgs()
3739
/// Initializes a new instance of the <see cref="KeyboardInputEventArgs"/> class.
3840
/// </summary>
3941
/// <param name="rawInput">The raw input.</param>
40-
internal KeyboardInputEventArgs(ref RawInput rawInput)
41-
: base(ref rawInput)
42+
/// <param name="hwnd">The handle of the window that received the RawInput mesage.</param>
43+
internal KeyboardInputEventArgs(ref RawInput rawInput, IntPtr hwnd)
44+
: base(ref rawInput, hwnd)
4245
{
4346
Key = (Keys) rawInput.Data.Keyboard.VKey;
4447
MakeCode = rawInput.Data.Keyboard.MakeCode;

Source/SharpDX.RawInput/MouseInputEventArgs.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
// THE SOFTWARE.
20+
21+
using System;
22+
2023
namespace SharpDX.RawInput
2124
{
2225
/// <summary>
@@ -35,8 +38,9 @@ public MouseInputEventArgs()
3538
/// Initializes a new instance of the <see cref="MouseInputEventArgs"/> class.
3639
/// </summary>
3740
/// <param name="rawInput">The raw input.</param>
38-
internal MouseInputEventArgs(ref RawInput rawInput)
39-
: base(ref rawInput)
41+
/// <param name="hwnd">The handle of the window that received the RawInput mesage.</param>
42+
internal MouseInputEventArgs(ref RawInput rawInput, IntPtr hwnd)
43+
: base(ref rawInput, hwnd)
4044
{
4145
Mode = (MouseMode) rawInput.Data.Mouse.Flags;
4246
ButtonFlags = (MouseButtonFlags)rawInput.Data.Mouse.ButtonsData.ButtonFlags;

Source/SharpDX.RawInput/RawInputEventArgs.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ protected RawInputEventArgs()
3030
{
3131
}
3232

33-
internal RawInputEventArgs(ref RawInput rawInput)
33+
internal RawInputEventArgs(ref RawInput rawInput, IntPtr hwnd)
3434
{
3535
Device = rawInput.Header.Device;
36+
WindowHandle = hwnd;
3637
}
3738

3839
/// <summary>
@@ -42,5 +43,13 @@ internal RawInputEventArgs(ref RawInput rawInput)
4243
/// The device.
4344
/// </value>
4445
public IntPtr Device { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the handle of the window that received the RawInput mesage.
49+
/// </summary>
50+
/// <value>
51+
/// The window handle.
52+
/// </value>
53+
public IntPtr WindowHandle { get; set; }
4554
}
4655
}

0 commit comments

Comments
 (0)