1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Server/Events/EventHidKeyboard.cs Thu Aug 18 18:49:03 2016 +0200
1.3 @@ -0,0 +1,138 @@
1.4 +using System;
1.5 +using System.Collections.Generic;
1.6 +using System.Linq;
1.7 +using System.Text;
1.8 +using System.Threading.Tasks;
1.9 +using System.Runtime.Serialization;
1.10 +using System.Windows.Forms;
1.11 +using Ear = SharpLib.Ear;
1.12 +using Hid = SharpLib.Hid;
1.13 +
1.14 +namespace SharpDisplayManager
1.15 +{
1.16 + [DataContract]
1.17 + [Ear.AttributeObject(Id = "Event.Hid.Keyboard", Name = "HID Keyboard", Description = "Corresponding HID message received.")]
1.18 + public class EventHidKeyboard : Ear.Event
1.19 + {
1.20 + public EventHidKeyboard()
1.21 + {
1.22 + }
1.23 +
1.24 + [DataMember]
1.25 + [Ear.AttributeObjectProperty
1.26 + (
1.27 + Id = "HID.Keyboard.Key",
1.28 + Name = "Key",
1.29 + Description = "The virtual key code."
1.30 + )]
1.31 + public Keys Key { get; set; }
1.32 +
1.33 + [DataMember]
1.34 + [Ear.AttributeObjectProperty
1.35 + (
1.36 + Id = "HID.Keyboard.IsKeyUp",
1.37 + Name = "Key Up",
1.38 + Description = "Key up if set, key down otherwise."
1.39 + )]
1.40 + public bool IsKeyUp { get; set; } = true;
1.41 +
1.42 + [DataMember]
1.43 + [Ear.AttributeObjectProperty
1.44 + (
1.45 + Id = "HID.Keyboard.HasModifierShift",
1.46 + Name = "Shift",
1.47 + Description = "Shift modifier applied."
1.48 + )]
1.49 + public bool HasModifierShift { get; set; } = false;
1.50 +
1.51 + [DataMember]
1.52 + [Ear.AttributeObjectProperty
1.53 + (
1.54 + Id = "HID.Keyboard.HasModifierControl",
1.55 + Name = "Control",
1.56 + Description = "Control modifier applied."
1.57 + )]
1.58 + public bool HasModifierControl { get; set; } = false;
1.59 +
1.60 + [DataMember]
1.61 + [Ear.AttributeObjectProperty
1.62 + (
1.63 + Id = "HID.Keyboard.HasModifierAlt",
1.64 + Name = "Alt",
1.65 + Description = "Alt modifier applied."
1.66 + )]
1.67 + public bool HasModifierAlt { get; set; } = false;
1.68 +
1.69 + [DataMember]
1.70 + [Ear.AttributeObjectProperty
1.71 + (
1.72 + Id = "HID.Keyboard.HasModifierWindows",
1.73 + Name = "Windows",
1.74 + Description = "Windows modifier applied."
1.75 + )]
1.76 + public bool HasModifierWindows { get; set; } = false;
1.77 +
1.78 +
1.79 +
1.80 + /// <summary>
1.81 + /// Make sure we distinguish between various configuration of this event
1.82 + /// </summary>
1.83 + /// <returns></returns>
1.84 + public override string Brief()
1.85 + {
1.86 + string brief = Name + ": " + Key.ToString();
1.87 +
1.88 + if (IsKeyUp)
1.89 + {
1.90 + brief += " (UP)";
1.91 + }
1.92 + else
1.93 + {
1.94 + brief += " (DOWN)";
1.95 + }
1.96 +
1.97 + if (HasModifierAlt)
1.98 + {
1.99 + brief += " + ALT";
1.100 + }
1.101 +
1.102 + if (HasModifierControl)
1.103 + {
1.104 + brief += " + CTRL";
1.105 + }
1.106 +
1.107 + if (HasModifierShift)
1.108 + {
1.109 + brief += " + SHIFT";
1.110 + }
1.111 +
1.112 + if (HasModifierWindows)
1.113 + {
1.114 + brief += " + WIN";
1.115 + }
1.116 +
1.117 + return brief;
1.118 + }
1.119 +
1.120 + /// <summary>
1.121 + ///
1.122 + /// </summary>
1.123 + /// <param name="obj"></param>
1.124 + /// <returns></returns>
1.125 + public override bool Equals(object obj)
1.126 + {
1.127 + if (obj is EventHidKeyboard)
1.128 + {
1.129 + EventHidKeyboard e = (EventHidKeyboard)obj;
1.130 + return e.Key == Key
1.131 + && e.IsKeyUp == IsKeyUp
1.132 + && e.HasModifierAlt == HasModifierAlt
1.133 + && e.HasModifierControl == HasModifierControl
1.134 + && e.HasModifierShift == HasModifierShift
1.135 + && e.HasModifierWindows == HasModifierWindows;
1.136 + }
1.137 +
1.138 + return false;
1.139 + }
1.140 + }
1.141 +}