RemoteControlDevice.cs
changeset 29 7679a5ab194b
parent 28 6af1cbb3beb4
child 30 8ce9bdc9c5b5
     1.1 --- a/RemoteControlDevice.cs	Sat Dec 06 22:59:55 2014 +0100
     1.2 +++ b/RemoteControlDevice.cs	Sat Dec 06 23:34:02 2014 +0100
     1.3 @@ -166,6 +166,8 @@
     1.4          /// <returns></returns>
     1.5          public delegate bool HidUsageHandler(ushort aUsage);
     1.6  
     1.7 +        Hid.HidHandler iHidHandler;
     1.8 +
     1.9  
    1.10          //-------------------------------------------------------------
    1.11          // constructors
    1.12 @@ -216,10 +218,12 @@
    1.13              //rid[i].hwndTarget = aHWND;
    1.14  
    1.15  
    1.16 -            if (!Function.RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
    1.17 +            iHidHandler = new Hid.HidHandler(rid);
    1.18 +            if (!iHidHandler.IsRegistered)
    1.19              {
    1.20 -                throw new ApplicationException("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString());
    1.21 +                Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString());
    1.22              }
    1.23 +            iHidHandler.OnHidEvent += HandleHidEvent;
    1.24          }
    1.25  
    1.26  
    1.27 @@ -367,31 +371,35 @@
    1.28              }
    1.29          }
    1.30  
    1.31 -
    1.32 +        /// <summary>
    1.33 +        /// 
    1.34 +        /// </summary>
    1.35 +        /// <param name="message"></param>
    1.36          private void ProcessInputCommand(ref Message message)
    1.37          {
    1.38              //We received a WM_INPUT message
    1.39              Debug.WriteLine("================WM_INPUT================");
    1.40  
    1.41 -            Hid.HidEvent hidEvent = new Hid.HidEvent(message);
    1.42 -            hidEvent.DebugWrite();
    1.43 +            iHidHandler.ProcessInput(message);
    1.44  
    1.45 -            if (!hidEvent.IsValid || !hidEvent.IsGeneric)
    1.46 -            {
    1.47 -                Debug.WriteLine("Skipping HID message.");
    1.48 -                return;
    1.49 -            }
    1.50 +        }
    1.51  
    1.52 -
    1.53 +        /// <summary>
    1.54 +        /// 
    1.55 +        /// </summary>
    1.56 +        /// <param name="aSender"></param>
    1.57 +        /// <param name="aHidEvent"></param>
    1.58 +        void HandleHidEvent(object aSender, Hid.HidEvent aHidEvent)
    1.59 +        {
    1.60              HidUsageHandler usagePageHandler = null;
    1.61  
    1.62              //Check if this an MCE remote HID message
    1.63 -            if (hidEvent.UsagePage == (ushort)Hid.UsagePage.MceRemote && hidEvent.UsageCollection == (ushort)Hid.UsageIdMce.MceRemote)
    1.64 +            if (aHidEvent.UsagePage == (ushort)Hid.UsagePage.MceRemote && aHidEvent.UsageCollection == (ushort)Hid.UsageIdMce.MceRemote)
    1.65              {
    1.66                  usagePageHandler = HidMceRemoteHandler;
    1.67              }
    1.68              //Check if this is a consumer control HID message
    1.69 -            else if (hidEvent.UsagePage == (ushort)Hid.UsagePage.Consumer && hidEvent.UsageCollection == (ushort)Hid.UsageCollectionConsumer.ConsumerControl)
    1.70 +            else if (aHidEvent.UsagePage == (ushort)Hid.UsagePage.Consumer && aHidEvent.UsageCollection == (ushort)Hid.UsageCollectionConsumer.ConsumerControl)
    1.71              {
    1.72                  usagePageHandler = HidConsumerDeviceHandler;
    1.73              }
    1.74 @@ -402,7 +410,7 @@
    1.75                  return;
    1.76              }
    1.77  
    1.78 -            foreach (ushort usage in hidEvent.Usages)
    1.79 +            foreach (ushort usage in aHidEvent.Usages)
    1.80              {
    1.81                  usagePageHandler(usage);
    1.82              }