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