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
26
public ushort UsageCollection { get; set; }
27
28
29
public ushort Usage { get; set; }
30
31
32
public Keys Key { get; set; }
33
34
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
44
public bool IsMouse { get; set; }
45
46
47
public bool IsKeyboard { get; set; }
48
49
50
public bool IsGeneric { get; set; }
51
52
53
public bool HasModifierShift { get; set; } = false;
54
55
56
public bool HasModifierControl { get; set; } = false;
57
58
59
public bool HasModifierAlt { get; set; } = false;
60
61
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
127
///
128
129
/// <param name="obj"></param>
130
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