Server/Events/EventHidKeyboard.cs
author Stephane Lenclud
Fri, 19 Aug 2016 17:12:54 +0200
changeset 243 cc2251d065db
permissions -rw-r--r--
Optical drive eject action now functional.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.Runtime.Serialization;
     7 using System.Windows.Forms;
     8 using Ear = SharpLib.Ear;
     9 using Hid = SharpLib.Hid;
    10 
    11 namespace SharpDisplayManager
    12 {
    13     [DataContract]
    14     [Ear.AttributeObject(Id = "Event.Hid.Keyboard", Name = "HID Keyboard", Description = "Corresponding HID message received.")]
    15     public class EventHidKeyboard : Ear.Event
    16     {
    17         public EventHidKeyboard()
    18         {
    19         }
    20 
    21         [DataMember]
    22         [Ear.AttributeObjectProperty
    23             (
    24             Id = "HID.Keyboard.Key",
    25             Name = "Key",
    26             Description = "The virtual key code."
    27             )]
    28         public Keys Key { get; set; }
    29 
    30         [DataMember]
    31         [Ear.AttributeObjectProperty
    32             (
    33             Id = "HID.Keyboard.IsKeyUp",
    34             Name = "Key Up",
    35             Description = "Key up if set, key down otherwise."
    36             )]
    37         public bool IsKeyUp { get; set; } = true;
    38 
    39         [DataMember]
    40         [Ear.AttributeObjectProperty
    41             (
    42             Id = "HID.Keyboard.HasModifierShift",
    43             Name = "Shift",
    44             Description = "Shift modifier applied."
    45             )]
    46         public bool HasModifierShift { get; set; } = false;
    47 
    48         [DataMember]
    49         [Ear.AttributeObjectProperty
    50             (
    51             Id = "HID.Keyboard.HasModifierControl",
    52             Name = "Control",
    53             Description = "Control modifier applied."
    54             )]
    55         public bool HasModifierControl { get; set; } = false;
    56 
    57         [DataMember]
    58         [Ear.AttributeObjectProperty
    59             (
    60             Id = "HID.Keyboard.HasModifierAlt",
    61             Name = "Alt",
    62             Description = "Alt modifier applied."
    63             )]
    64         public bool HasModifierAlt { get; set; } = false;
    65 
    66         [DataMember]
    67         [Ear.AttributeObjectProperty
    68             (
    69             Id = "HID.Keyboard.HasModifierWindows",
    70             Name = "Windows",
    71             Description = "Windows modifier applied."
    72             )]
    73         public bool HasModifierWindows { get; set; } = false;
    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 + ": " + Key.ToString();
    84 
    85             if (IsKeyUp)
    86             {
    87                 brief += " (UP)";
    88             }
    89             else
    90             {
    91                 brief += " (DOWN)";
    92             }
    93 
    94             if (HasModifierAlt)
    95             {
    96                 brief += " + ALT";
    97             }
    98 
    99             if (HasModifierControl)
   100             {
   101                 brief += " + CTRL";
   102             }
   103 
   104             if (HasModifierShift)
   105             {
   106                 brief += " + SHIFT";
   107             }
   108 
   109             if (HasModifierWindows)
   110             {
   111                 brief += " + WIN";
   112             }
   113 
   114             return brief;
   115         }
   116 
   117         /// <summary>
   118         ///
   119         /// </summary>
   120         /// <param name="obj"></param>
   121         /// <returns></returns>
   122         public override bool Equals(object obj)
   123         {
   124             if (obj is EventHidKeyboard)
   125             {
   126                 EventHidKeyboard e = (EventHidKeyboard)obj;
   127                 return  e.Key == Key
   128                         && e.IsKeyUp == IsKeyUp
   129                         && e.HasModifierAlt == HasModifierAlt
   130                         && e.HasModifierControl == HasModifierControl
   131                         && e.HasModifierShift == HasModifierShift
   132                         && e.HasModifierWindows == HasModifierWindows;
   133             }
   134 
   135             return false;
   136         }
   137     }
   138 }