HidHandler.cs
author sl
Mon, 22 Dec 2014 11:40:23 +0100
changeset 36 259e823a8e84
child 40 b3e177062849
permissions -rw-r--r--
Renaming form.
     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     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 }