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