HidHandler.cs
author sl
Tue, 23 Dec 2014 21:17:17 +0100
changeset 40 b3e177062849
parent 29 7679a5ab194b
child 41 dd603eba46ca
permissions -rw-r--r--
Adding colums to our listview.
     1 using System;
     2 using System.Windows.Forms;
     3 using System.Runtime.InteropServices;
     4 using System.Diagnostics;
     5 using System.Text;
     6 using Microsoft.Win32.SafeHandles;
     7 using Win32;
     8 using System.Collections.Generic;
     9 
    10 
    11 namespace Hid
    12 {
    13 
    14 
    15     /// <summary>
    16     /// Our HID handler manages raw input registrations, processes WM_INPUT messages and broadcasts HID events in return.
    17     /// </summary>
    18     public class HidHandler
    19     {
    20         public delegate void HidEventHandler(object aSender, HidEvent aHidEvent);
    21         public event HidEventHandler OnHidEvent;
    22 
    23         public bool IsRegistered { get; private set; }
    24 
    25         public HidHandler(RAWINPUTDEVICE[] aRawInputDevices)
    26         {
    27             IsRegistered = Function.RegisterRawInputDevices(aRawInputDevices, (uint)aRawInputDevices.Length, (uint)Marshal.SizeOf(aRawInputDevices[0]));
    28         }
    29 
    30 
    31         public void ProcessInput(Message aMessage)
    32         {
    33             Hid.HidEvent hidEvent = new Hid.HidEvent(aMessage);
    34             hidEvent.DebugWrite();
    35 
    36             if (!hidEvent.IsValid || !hidEvent.IsGeneric)
    37             {
    38                 Debug.WriteLine("Skipping HID message.");
    39                 return;
    40             }
    41 
    42             //Broadcast our events
    43             OnHidEvent(this, hidEvent);    
    44         }
    45 
    46     }
    47 
    48 }