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

Commit

Permalink
RawInputEventArgs (and thus also HidInputEventArgs, KeyboardInputEven…
Browse files Browse the repository at this point in the history
…tArgs, and MouseInputEventArgs) now has a WindowHandle property that can be used to retrieve the handle of the window that received the raw input event.
  • Loading branch information
waltdestler committed May 29, 2016
1 parent c5a6efa commit 7a1149c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
11 changes: 6 additions & 5 deletions Source/SharpDX.RawInput/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ public static void RegisterDevice(UsagePage usagePage, UsageId usageId, DeviceFl
/// Handles a RawInput message manually.
/// </summary>
/// <param name="rawInputMessagePointer">A pointer to a RawInput message.</param>
/// <param name="hwnd">The handle of the window that received the RawInput message.</param>
/// <remarks>
/// This method can be used directly when handling RawInput messages from non-WinForms application.
/// </remarks>
public static void HandleMessage(IntPtr rawInputMessagePointer)
public static void HandleMessage(IntPtr rawInputMessagePointer, IntPtr hwnd)
{
unsafe
{
Expand All @@ -165,15 +166,15 @@ public static void HandleMessage(IntPtr rawInputMessagePointer)
{
case DeviceType.HumanInputDevice:
if (RawInput != null)
RawInput(null, new HidInputEventArgs(ref *rawInput));
RawInput(null, new HidInputEventArgs(ref *rawInput, hwnd));
break;
case DeviceType.Keyboard:
if (KeyboardInput != null)
KeyboardInput(null, new KeyboardInputEventArgs(ref *rawInput));
KeyboardInput(null, new KeyboardInputEventArgs(ref *rawInput, hwnd));
break;
case DeviceType.Mouse:
if (MouseInput != null)
MouseInput(null, new MouseInputEventArgs(ref *rawInput));
MouseInput(null, new MouseInputEventArgs(ref *rawInput, hwnd));
break;
}
}
Expand All @@ -193,7 +194,7 @@ public virtual bool PreFilterMessage(ref Message m)
{
// Handle only WM_INPUT messages
if (m.Msg == WmInput)
HandleMessage(m.LParam);
HandleMessage(m.LParam, m.HWnd);
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion Source/SharpDX.RawInput/HidInputEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public HidInputEventArgs()
/// Initializes a new instance of the <see cref="HidInputEventArgs"/> class.
/// </summary>
/// <param name="rawInput">The raw input.</param>
internal HidInputEventArgs(ref RawInput rawInput) : base(ref rawInput)
/// <param name="hwnd">The handle of the window that received the RawInput mesage.</param>
internal HidInputEventArgs(ref RawInput rawInput, IntPtr hwnd) : base(ref rawInput, hwnd)
{
Count = rawInput.Data.Hid.Count;
DataSize = rawInput.Data.Hid.SizeHid;
Expand Down
7 changes: 5 additions & 2 deletions Source/SharpDX.RawInput/KeyboardInputEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.Windows.Forms;

namespace SharpDX.RawInput
Expand All @@ -37,8 +39,9 @@ public KeyboardInputEventArgs()
/// Initializes a new instance of the <see cref="KeyboardInputEventArgs"/> class.
/// </summary>
/// <param name="rawInput">The raw input.</param>
internal KeyboardInputEventArgs(ref RawInput rawInput)
: base(ref rawInput)
/// <param name="hwnd">The handle of the window that received the RawInput mesage.</param>
internal KeyboardInputEventArgs(ref RawInput rawInput, IntPtr hwnd)
: base(ref rawInput, hwnd)
{
Key = (Keys) rawInput.Data.Keyboard.VKey;
MakeCode = rawInput.Data.Keyboard.MakeCode;
Expand Down
8 changes: 6 additions & 2 deletions Source/SharpDX.RawInput/MouseInputEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;

namespace SharpDX.RawInput
{
/// <summary>
Expand All @@ -35,8 +38,9 @@ public MouseInputEventArgs()
/// Initializes a new instance of the <see cref="MouseInputEventArgs"/> class.
/// </summary>
/// <param name="rawInput">The raw input.</param>
internal MouseInputEventArgs(ref RawInput rawInput)
: base(ref rawInput)
/// <param name="hwnd">The handle of the window that received the RawInput mesage.</param>
internal MouseInputEventArgs(ref RawInput rawInput, IntPtr hwnd)
: base(ref rawInput, hwnd)
{
Mode = (MouseMode) rawInput.Data.Mouse.Flags;
ButtonFlags = (MouseButtonFlags)rawInput.Data.Mouse.ButtonsData.ButtonFlags;
Expand Down
11 changes: 10 additions & 1 deletion Source/SharpDX.RawInput/RawInputEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ protected RawInputEventArgs()
{
}

internal RawInputEventArgs(ref RawInput rawInput)
internal RawInputEventArgs(ref RawInput rawInput, IntPtr hwnd)
{
Device = rawInput.Header.Device;
WindowHandle = hwnd;
}

/// <summary>
Expand All @@ -42,5 +43,13 @@ internal RawInputEventArgs(ref RawInput rawInput)
/// The device.
/// </value>
public IntPtr Device { get; set; }

/// <summary>
/// Gets or sets the handle of the window that received the RawInput mesage.
/// </summary>
/// <value>
/// The window handle.
/// </value>
public IntPtr WindowHandle { get; set; }
}
}

0 comments on commit 7a1149c

Please sign in to comment.