sl@0
|
1 |
using System;
|
sl@0
|
2 |
using System.Drawing;
|
sl@0
|
3 |
using System.Collections;
|
sl@0
|
4 |
using System.ComponentModel;
|
sl@0
|
5 |
using System.Windows.Forms;
|
sl@0
|
6 |
using System.Data;
|
sl@6
|
7 |
using Devices.RemoteControl;
|
sl@0
|
8 |
|
sl@0
|
9 |
namespace RemoteControlSample
|
sl@0
|
10 |
{
|
sl@0
|
11 |
/// <summary>
|
sl@0
|
12 |
/// Summary description for Form1.
|
sl@0
|
13 |
/// </summary>
|
sl@36
|
14 |
public class MainForm : System.Windows.Forms.Form
|
sl@0
|
15 |
{
|
sl@0
|
16 |
/// <summary>
|
sl@0
|
17 |
/// Required designer variable.
|
sl@0
|
18 |
/// </summary>
|
sl@38
|
19 |
private System.ComponentModel.Container components = null;
|
sl@38
|
20 |
private RemoteControlDevice _remote;
|
sl@38
|
21 |
private Label labelButtonName;
|
sl@38
|
22 |
private Label labelDeviceName;
|
sl@39
|
23 |
private ListView listViewEvents;
|
StephaneLenclud@49
|
24 |
private ColumnHeader columnHeaderUsages;
|
sl@40
|
25 |
private ColumnHeader columnHeaderUsagePage;
|
sl@40
|
26 |
private ColumnHeader columnHeaderUsageCollection;
|
sl@42
|
27 |
private ColumnHeader columnHeaderRepeat;
|
sl@44
|
28 |
private ColumnHeader columnHeaderTime;
|
StephaneLenclud@49
|
29 |
private Button buttonClear;
|
StephaneLenclud@49
|
30 |
private ColumnHeader columnHeaderInputReport;
|
sl@0
|
31 |
private Timer _timer;
|
sl@0
|
32 |
|
sl@41
|
33 |
public delegate void OnHidEventDelegate(object aSender, Hid.HidEvent aHidEvent);
|
sl@41
|
34 |
|
sl@36
|
35 |
public MainForm()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
//
|
sl@0
|
38 |
// Required for Windows Form Designer support
|
sl@0
|
39 |
//
|
sl@0
|
40 |
InitializeComponent();
|
sl@0
|
41 |
|
sl@0
|
42 |
_timer = new Timer();
|
sl@0
|
43 |
_timer.Interval = 3000;
|
sl@0
|
44 |
_timer.Enabled = false;
|
sl@15
|
45 |
_timer.Tick +=new EventHandler(_timer_Tick);
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
/// <summary>
|
sl@0
|
49 |
/// Clean up any resources being used.
|
sl@0
|
50 |
/// </summary>
|
sl@0
|
51 |
protected override void Dispose( bool disposing )
|
sl@0
|
52 |
{
|
sl@0
|
53 |
if( disposing )
|
sl@0
|
54 |
{
|
sl@6
|
55 |
if (components != null)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
components.Dispose();
|
sl@0
|
58 |
}
|
sl@0
|
59 |
}
|
sl@0
|
60 |
base.Dispose( disposing );
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
#region Windows Form Designer generated code
|
sl@0
|
64 |
/// <summary>
|
sl@0
|
65 |
/// Required method for Designer support - do not modify
|
sl@0
|
66 |
/// the contents of this method with the code editor.
|
sl@0
|
67 |
/// </summary>
|
sl@0
|
68 |
private void InitializeComponent()
|
sl@0
|
69 |
{
|
StephaneLenclud@49
|
70 |
this.labelButtonName = new System.Windows.Forms.Label();
|
StephaneLenclud@49
|
71 |
this.labelDeviceName = new System.Windows.Forms.Label();
|
StephaneLenclud@49
|
72 |
this.listViewEvents = new System.Windows.Forms.ListView();
|
StephaneLenclud@49
|
73 |
this.columnHeaderUsages = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
StephaneLenclud@49
|
74 |
this.columnHeaderUsagePage = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
StephaneLenclud@49
|
75 |
this.columnHeaderUsageCollection = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
StephaneLenclud@49
|
76 |
this.columnHeaderRepeat = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
StephaneLenclud@49
|
77 |
this.columnHeaderTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
StephaneLenclud@49
|
78 |
this.buttonClear = new System.Windows.Forms.Button();
|
StephaneLenclud@49
|
79 |
this.columnHeaderInputReport = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
StephaneLenclud@49
|
80 |
this.SuspendLayout();
|
StephaneLenclud@49
|
81 |
//
|
StephaneLenclud@49
|
82 |
// labelButtonName
|
StephaneLenclud@49
|
83 |
//
|
StephaneLenclud@49
|
84 |
this.labelButtonName.AutoSize = true;
|
StephaneLenclud@49
|
85 |
this.labelButtonName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
StephaneLenclud@49
|
86 |
this.labelButtonName.Location = new System.Drawing.Point(811, 55);
|
StephaneLenclud@49
|
87 |
this.labelButtonName.Name = "labelButtonName";
|
StephaneLenclud@49
|
88 |
this.labelButtonName.Size = new System.Drawing.Size(103, 20);
|
StephaneLenclud@49
|
89 |
this.labelButtonName.TabIndex = 0;
|
StephaneLenclud@49
|
90 |
this.labelButtonName.Text = "Button Name";
|
StephaneLenclud@49
|
91 |
//
|
StephaneLenclud@49
|
92 |
// labelDeviceName
|
StephaneLenclud@49
|
93 |
//
|
StephaneLenclud@49
|
94 |
this.labelDeviceName.AutoSize = true;
|
StephaneLenclud@49
|
95 |
this.labelDeviceName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
StephaneLenclud@49
|
96 |
this.labelDeviceName.Location = new System.Drawing.Point(811, 35);
|
StephaneLenclud@49
|
97 |
this.labelDeviceName.Name = "labelDeviceName";
|
StephaneLenclud@49
|
98 |
this.labelDeviceName.Size = new System.Drawing.Size(103, 20);
|
StephaneLenclud@49
|
99 |
this.labelDeviceName.TabIndex = 1;
|
StephaneLenclud@49
|
100 |
this.labelDeviceName.Text = "Device Name";
|
StephaneLenclud@49
|
101 |
//
|
StephaneLenclud@49
|
102 |
// listViewEvents
|
StephaneLenclud@49
|
103 |
//
|
StephaneLenclud@49
|
104 |
this.listViewEvents.Alignment = System.Windows.Forms.ListViewAlignment.Left;
|
StephaneLenclud@49
|
105 |
this.listViewEvents.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
sl@39
|
106 |
| System.Windows.Forms.AnchorStyles.Left)));
|
StephaneLenclud@49
|
107 |
this.listViewEvents.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
StephaneLenclud@49
|
108 |
this.listViewEvents.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
StephaneLenclud@49
|
109 |
this.columnHeaderUsages,
|
StephaneLenclud@49
|
110 |
this.columnHeaderInputReport,
|
sl@40
|
111 |
this.columnHeaderUsagePage,
|
sl@42
|
112 |
this.columnHeaderUsageCollection,
|
sl@44
|
113 |
this.columnHeaderRepeat,
|
sl@44
|
114 |
this.columnHeaderTime});
|
StephaneLenclud@49
|
115 |
this.listViewEvents.GridLines = true;
|
StephaneLenclud@49
|
116 |
this.listViewEvents.Location = new System.Drawing.Point(12, 12);
|
StephaneLenclud@49
|
117 |
this.listViewEvents.Name = "listViewEvents";
|
StephaneLenclud@49
|
118 |
this.listViewEvents.Size = new System.Drawing.Size(766, 369);
|
StephaneLenclud@49
|
119 |
this.listViewEvents.TabIndex = 2;
|
StephaneLenclud@49
|
120 |
this.listViewEvents.UseCompatibleStateImageBehavior = false;
|
StephaneLenclud@49
|
121 |
this.listViewEvents.View = System.Windows.Forms.View.Details;
|
StephaneLenclud@49
|
122 |
//
|
StephaneLenclud@49
|
123 |
// columnHeaderUsages
|
StephaneLenclud@49
|
124 |
//
|
StephaneLenclud@49
|
125 |
this.columnHeaderUsages.Text = "Usages";
|
StephaneLenclud@49
|
126 |
this.columnHeaderUsages.Width = 180;
|
StephaneLenclud@49
|
127 |
//
|
StephaneLenclud@49
|
128 |
// columnHeaderUsagePage
|
StephaneLenclud@49
|
129 |
//
|
StephaneLenclud@49
|
130 |
this.columnHeaderUsagePage.Text = "Usage Page";
|
StephaneLenclud@49
|
131 |
this.columnHeaderUsagePage.Width = 87;
|
StephaneLenclud@49
|
132 |
//
|
StephaneLenclud@49
|
133 |
// columnHeaderUsageCollection
|
StephaneLenclud@49
|
134 |
//
|
StephaneLenclud@49
|
135 |
this.columnHeaderUsageCollection.Text = "Usage Collection";
|
StephaneLenclud@49
|
136 |
this.columnHeaderUsageCollection.Width = 134;
|
StephaneLenclud@49
|
137 |
//
|
StephaneLenclud@49
|
138 |
// columnHeaderRepeat
|
StephaneLenclud@49
|
139 |
//
|
StephaneLenclud@49
|
140 |
this.columnHeaderRepeat.Text = "Repeat";
|
StephaneLenclud@49
|
141 |
this.columnHeaderRepeat.Width = 68;
|
StephaneLenclud@49
|
142 |
//
|
StephaneLenclud@49
|
143 |
// columnHeaderTime
|
StephaneLenclud@49
|
144 |
//
|
StephaneLenclud@49
|
145 |
this.columnHeaderTime.Text = "Time";
|
StephaneLenclud@49
|
146 |
this.columnHeaderTime.Width = 76;
|
StephaneLenclud@49
|
147 |
//
|
StephaneLenclud@49
|
148 |
// buttonClear
|
StephaneLenclud@49
|
149 |
//
|
StephaneLenclud@49
|
150 |
this.buttonClear.Location = new System.Drawing.Point(839, 9);
|
StephaneLenclud@49
|
151 |
this.buttonClear.Name = "buttonClear";
|
StephaneLenclud@49
|
152 |
this.buttonClear.Size = new System.Drawing.Size(75, 23);
|
StephaneLenclud@49
|
153 |
this.buttonClear.TabIndex = 3;
|
StephaneLenclud@49
|
154 |
this.buttonClear.Text = "Clear";
|
StephaneLenclud@49
|
155 |
this.buttonClear.UseVisualStyleBackColor = true;
|
StephaneLenclud@49
|
156 |
this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
|
StephaneLenclud@49
|
157 |
//
|
StephaneLenclud@49
|
158 |
// columnHeaderInputReport
|
StephaneLenclud@49
|
159 |
//
|
StephaneLenclud@49
|
160 |
this.columnHeaderInputReport.Text = "Input Report";
|
StephaneLenclud@49
|
161 |
this.columnHeaderInputReport.Width = 176;
|
StephaneLenclud@49
|
162 |
//
|
StephaneLenclud@49
|
163 |
// MainForm
|
StephaneLenclud@49
|
164 |
//
|
StephaneLenclud@49
|
165 |
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
|
StephaneLenclud@49
|
166 |
this.BackColor = System.Drawing.SystemColors.Control;
|
StephaneLenclud@49
|
167 |
this.ClientSize = new System.Drawing.Size(926, 393);
|
StephaneLenclud@49
|
168 |
this.Controls.Add(this.buttonClear);
|
StephaneLenclud@49
|
169 |
this.Controls.Add(this.listViewEvents);
|
StephaneLenclud@49
|
170 |
this.Controls.Add(this.labelDeviceName);
|
StephaneLenclud@49
|
171 |
this.Controls.Add(this.labelButtonName);
|
StephaneLenclud@49
|
172 |
this.Name = "MainForm";
|
StephaneLenclud@49
|
173 |
this.Text = "Remote Control Sample";
|
StephaneLenclud@49
|
174 |
this.Load += new System.EventHandler(this.Form1_Load);
|
StephaneLenclud@49
|
175 |
this.ResumeLayout(false);
|
StephaneLenclud@49
|
176 |
this.PerformLayout();
|
sl@0
|
177 |
|
sl@0
|
178 |
}
|
sl@6
|
179 |
#endregion Windows Form Designer generated code
|
sl@0
|
180 |
|
sl@0
|
181 |
/// <summary>
|
sl@0
|
182 |
/// The main entry point for the application.
|
sl@0
|
183 |
/// </summary>
|
sl@0
|
184 |
[STAThread]
|
sl@6
|
185 |
static void Main()
|
sl@0
|
186 |
{
|
sl@36
|
187 |
Application.Run(new MainForm());
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
private void Form1_Load(object sender, System.EventArgs e)
|
sl@0
|
191 |
{
|
sl@15
|
192 |
_remote = new RemoteControlDevice(this.Handle);
|
sl@15
|
193 |
_remote.ButtonPressed += new Devices.RemoteControl.RemoteControlDevice.RemoteControlDeviceEventHandler(_remote_ButtonPressed);
|
sl@41
|
194 |
_remote.iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@41
|
197 |
public void HandleHidEventThreadSafe(object aSender, Hid.HidEvent aHidEvent)
|
sl@40
|
198 |
{
|
sl@42
|
199 |
if (aHidEvent.IsStray)
|
sl@42
|
200 |
{
|
sl@42
|
201 |
//Stray event just ignore it
|
sl@42
|
202 |
return;
|
sl@42
|
203 |
}
|
sl@42
|
204 |
|
sl@41
|
205 |
if (this.InvokeRequired)
|
sl@41
|
206 |
{
|
sl@41
|
207 |
//Not in the proper thread, invoke ourselves
|
sl@41
|
208 |
OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe);
|
sl@41
|
209 |
this.Invoke(d, new object[] { aSender, aHidEvent });
|
sl@41
|
210 |
}
|
sl@41
|
211 |
else
|
sl@41
|
212 |
{
|
sl@41
|
213 |
//We are in the proper thread
|
sl@42
|
214 |
listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem());
|
sl@41
|
215 |
}
|
sl@40
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
protected override void WndProc(ref Message message)
|
sl@0
|
219 |
{
|
sl@15
|
220 |
if (_remote != null)
|
sl@15
|
221 |
{
|
sl@15
|
222 |
_remote.ProcessMessage(message);
|
sl@15
|
223 |
}
|
sl@0
|
224 |
base.WndProc(ref message);
|
sl@0
|
225 |
}
|
sl@0
|
226 |
|
sl@19
|
227 |
private bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
|
sl@0
|
228 |
{
|
sl@41
|
229 |
//Set text from here was disabled because of threading issues
|
sl@41
|
230 |
//That whole thing should be removed anyway
|
sl@19
|
231 |
bool processed = false;
|
sl@0
|
232 |
_timer.Enabled = false;
|
sl@3
|
233 |
if (e.Button != RemoteControlButton.Unknown)
|
sl@3
|
234 |
{
|
sl@41
|
235 |
//labelButtonName.Text = e.Button.ToString();
|
sl@19
|
236 |
processed = true;
|
sl@3
|
237 |
}
|
sl@30
|
238 |
else if (e.MceButton != Hid.UsageTables.WindowsMediaCenterRemoteControl.Null)
|
sl@3
|
239 |
{
|
sl@5
|
240 |
//Display MCE button name
|
sl@41
|
241 |
//labelButtonName.Text = e.MceButton.ToString();
|
sl@5
|
242 |
//Check if this is an HP extension
|
sl@31
|
243 |
if (Enum.IsDefined(typeof(Hid.UsageTables.HpWindowsMediaCenterRemoteControl), (ushort)e.MceButton))
|
sl@5
|
244 |
{
|
sl@5
|
245 |
//Also display HP button name
|
sl@41
|
246 |
//labelButtonName.Text += " / HP:" + ((Hid.UsageTables.HpWindowsMediaCenterRemoteControl)e.MceButton).ToString();
|
sl@6
|
247 |
}
|
sl@19
|
248 |
|
sl@40
|
249 |
processed = true;
|
sl@19
|
250 |
}
|
sl@19
|
251 |
else if (e.ConsumerControl != Hid.UsageTables.ConsumerControl.Null)
|
sl@19
|
252 |
{
|
sl@19
|
253 |
//Display consumer control name
|
sl@41
|
254 |
//labelButtonName.Text = e.ConsumerControl.ToString();
|
sl@19
|
255 |
processed = true;
|
sl@3
|
256 |
}
|
sl@3
|
257 |
else
|
sl@3
|
258 |
{
|
sl@41
|
259 |
//labelButtonName.Text = "Unknown";
|
sl@3
|
260 |
}
|
sl@41
|
261 |
//labelDeviceName.Text = e.Device.ToString();
|
sl@0
|
262 |
_timer.Enabled = true;
|
sl@19
|
263 |
return processed;
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
private void _timer_Tick(object sender, EventArgs e)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
_timer.Enabled = false;
|
sl@38
|
269 |
labelButtonName.Text = "Ready...";
|
sl@0
|
270 |
}
|
sl@38
|
271 |
|
StephaneLenclud@49
|
272 |
private void buttonClear_Click(object sender, EventArgs e)
|
StephaneLenclud@49
|
273 |
{
|
StephaneLenclud@49
|
274 |
listViewEvents.Items.Clear();
|
StephaneLenclud@49
|
275 |
}
|
StephaneLenclud@49
|
276 |
|
sl@0
|
277 |
}
|
sl@0
|
278 |
}
|