Server/Events/EventHid.cs
author StephaneLenclud
Fri, 19 Aug 2016 19:28:03 +0200
changeset 245 448e6a616c22
child 246 30a221eecc06
permissions -rw-r--r--
Removing Input tab as we don't need to specific features anymore.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Reflection;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 using System.Runtime.Serialization;
     8 using System.Windows.Forms;
     9 using Ear = SharpLib.Ear;
    10 using Hid = SharpLib.Hid;
    11 
    12 namespace SharpDisplayManager
    13 {
    14     [DataContract]
    15     [Ear.AttributeObject(Id = "Event.Hid", Name = "HID", Description = "Corresponding HID message received.")]
    16     public class EventHid: Ear.Event
    17     {
    18         public EventHid()
    19         {
    20         }
    21 
    22         [DataMember]
    23         public ushort UsagePage { get; set; }
    24 
    25         [DataMember]
    26         public ushort UsageCollection { get; set; }
    27 
    28         [DataMember]
    29         public ushort Usage { get; set; }
    30 
    31         [DataMember]
    32         public Keys Key { get; set; }
    33 
    34         [DataMember]
    35         [Ear.AttributeObjectProperty
    36             (
    37             Id = "HID.Keyboard.IsKeyUp",
    38             Name = "Key Up",
    39             Description = "Key up if set, key down otherwise."
    40             )]
    41         public bool IsKeyUp { get; set; } = false;
    42 
    43         [DataMember]
    44         public bool IsMouse { get; set; }
    45 
    46         [DataMember]
    47         public bool IsKeyboard { get; set; }
    48 
    49         [DataMember]
    50         public bool IsGeneric { get; set; }
    51 
    52         [DataMember]
    53         public bool HasModifierShift { get; set; } = false;
    54 
    55         [DataMember]
    56         public bool HasModifierControl { get; set; } = false;
    57 
    58         [DataMember]
    59         public bool HasModifierAlt { get; set; } = false;
    60 
    61         [DataMember]
    62         public bool HasModifierWindows { get; set; } = false;
    63 
    64 
    65         protected override void DoConstruct()
    66         {
    67             base.DoConstruct();
    68             UpdateDynamicProperties();
    69         }
    70 
    71         private void UpdateDynamicProperties()
    72         {
    73             
    74         }
    75 
    76 
    77         /// <summary>
    78         /// Make sure we distinguish between various configuration of this event 
    79         /// </summary>
    80         /// <returns></returns>
    81         public override string Brief()
    82         {
    83             string brief = Name + ": ";
    84 
    85             if (IsKeyboard)
    86             {
    87                 brief += Key.ToString();
    88 
    89                 if (HasModifierAlt)
    90                 {
    91                     brief += " + ALT";
    92                 }
    93 
    94                 if (HasModifierControl)
    95                 {
    96                     brief += " + CTRL";
    97                 }
    98 
    99                 if (HasModifierShift)
   100                 {
   101                     brief += " + SHIFT";
   102                 }
   103 
   104                 if (HasModifierWindows)
   105                 {
   106                     brief += " + WIN";
   107                 }
   108             }
   109             else if (IsGeneric)
   110             {
   111                 
   112             }
   113 
   114             if (IsKeyUp)
   115             {
   116                 brief += " (UP)";
   117             }
   118             else
   119             {
   120                 brief += " (DOWN)";
   121             }
   122 
   123             return brief;
   124         }
   125 
   126         /// <summary>
   127         ///
   128         /// </summary>
   129         /// <param name="obj"></param>
   130         /// <returns></returns>
   131         public override bool Equals(object obj)
   132         {
   133             if (obj is EventHidKeyboard)
   134             {
   135                 EventHidKeyboard e = (EventHidKeyboard)obj;
   136                 return e.Key == Key
   137                         && e.IsKeyUp == IsKeyUp
   138                         && e.HasModifierAlt == HasModifierAlt
   139                         && e.HasModifierControl == HasModifierControl
   140                         && e.HasModifierShift == HasModifierShift
   141                         && e.HasModifierWindows == HasModifierWindows;
   142             }
   143 
   144             return false;
   145         }
   146     }
   147 }