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>
|
StephaneLenclud@60
|
14 |
public partial 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;
|
StephaneLenclud@60
|
23 |
private Button buttonClear;
|
StephaneLenclud@60
|
24 |
private TabControl tabControl;
|
StephaneLenclud@60
|
25 |
private TabPage tabPageMessages;
|
sl@39
|
26 |
private ListView listViewEvents;
|
StephaneLenclud@49
|
27 |
private ColumnHeader columnHeaderUsages;
|
StephaneLenclud@60
|
28 |
private ColumnHeader columnHeaderInputReport;
|
sl@40
|
29 |
private ColumnHeader columnHeaderUsagePage;
|
sl@40
|
30 |
private ColumnHeader columnHeaderUsageCollection;
|
sl@42
|
31 |
private ColumnHeader columnHeaderRepeat;
|
sl@44
|
32 |
private ColumnHeader columnHeaderTime;
|
StephaneLenclud@60
|
33 |
private TabPage tabPageDevices;
|
StephaneLenclud@60
|
34 |
private TreeView treeViewDevices;
|
sl@0
|
35 |
private Timer _timer;
|
sl@0
|
36 |
|
sl@41
|
37 |
public delegate void OnHidEventDelegate(object aSender, Hid.HidEvent aHidEvent);
|
sl@41
|
38 |
|
sl@36
|
39 |
public MainForm()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
//
|
sl@0
|
42 |
// Required for Windows Form Designer support
|
sl@0
|
43 |
//
|
sl@0
|
44 |
InitializeComponent();
|
sl@0
|
45 |
|
sl@0
|
46 |
_timer = new Timer();
|
sl@0
|
47 |
_timer.Interval = 3000;
|
sl@0
|
48 |
_timer.Enabled = false;
|
sl@15
|
49 |
_timer.Tick +=new EventHandler(_timer_Tick);
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
/// <summary>
|
sl@0
|
53 |
/// Clean up any resources being used.
|
sl@0
|
54 |
/// </summary>
|
sl@0
|
55 |
protected override void Dispose( bool disposing )
|
sl@0
|
56 |
{
|
sl@0
|
57 |
if( disposing )
|
sl@0
|
58 |
{
|
sl@6
|
59 |
if (components != null)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
components.Dispose();
|
sl@0
|
62 |
}
|
sl@0
|
63 |
}
|
sl@0
|
64 |
base.Dispose( disposing );
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
|
sl@0
|
68 |
/// <summary>
|
sl@0
|
69 |
/// The main entry point for the application.
|
sl@0
|
70 |
/// </summary>
|
sl@0
|
71 |
[STAThread]
|
sl@6
|
72 |
static void Main()
|
sl@0
|
73 |
{
|
StephaneLenclud@60
|
74 |
Application.EnableVisualStyles();
|
sl@36
|
75 |
Application.Run(new MainForm());
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
StephaneLenclud@60
|
78 |
private void MainForm_Load(object sender, System.EventArgs e)
|
sl@0
|
79 |
{
|
sl@15
|
80 |
_remote = new RemoteControlDevice(this.Handle);
|
sl@15
|
81 |
_remote.ButtonPressed += new Devices.RemoteControl.RemoteControlDevice.RemoteControlDeviceEventHandler(_remote_ButtonPressed);
|
StephaneLenclud@60
|
82 |
_remote.iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
|
StephaneLenclud@60
|
83 |
|
StephaneLenclud@60
|
84 |
//
|
StephaneLenclud@60
|
85 |
Win32.RawInput.PopulateDeviceList(treeViewDevices);
|
StephaneLenclud@60
|
86 |
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@41
|
89 |
public void HandleHidEventThreadSafe(object aSender, Hid.HidEvent aHidEvent)
|
sl@40
|
90 |
{
|
sl@42
|
91 |
if (aHidEvent.IsStray)
|
sl@42
|
92 |
{
|
sl@42
|
93 |
//Stray event just ignore it
|
sl@42
|
94 |
return;
|
sl@42
|
95 |
}
|
sl@42
|
96 |
|
sl@41
|
97 |
if (this.InvokeRequired)
|
sl@41
|
98 |
{
|
sl@41
|
99 |
//Not in the proper thread, invoke ourselves
|
sl@41
|
100 |
OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe);
|
sl@41
|
101 |
this.Invoke(d, new object[] { aSender, aHidEvent });
|
sl@41
|
102 |
}
|
sl@41
|
103 |
else
|
sl@41
|
104 |
{
|
sl@41
|
105 |
//We are in the proper thread
|
sl@42
|
106 |
listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem());
|
StephaneLenclud@67
|
107 |
toolStripStatusLabelDevice.Text = aHidEvent.Device.FriendlyName;
|
sl@41
|
108 |
}
|
sl@40
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
protected override void WndProc(ref Message message)
|
sl@0
|
112 |
{
|
sl@15
|
113 |
if (_remote != null)
|
sl@15
|
114 |
{
|
sl@15
|
115 |
_remote.ProcessMessage(message);
|
sl@15
|
116 |
}
|
sl@0
|
117 |
base.WndProc(ref message);
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@19
|
120 |
private bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
|
sl@0
|
121 |
{
|
sl@41
|
122 |
//Set text from here was disabled because of threading issues
|
sl@41
|
123 |
//That whole thing should be removed anyway
|
sl@19
|
124 |
bool processed = false;
|
sl@0
|
125 |
_timer.Enabled = false;
|
sl@3
|
126 |
if (e.Button != RemoteControlButton.Unknown)
|
sl@3
|
127 |
{
|
sl@41
|
128 |
//labelButtonName.Text = e.Button.ToString();
|
sl@19
|
129 |
processed = true;
|
sl@3
|
130 |
}
|
StephaneLenclud@66
|
131 |
else if (e.MceButton != Hid.Usage.WindowsMediaCenterRemoteControl.Null)
|
sl@3
|
132 |
{
|
sl@5
|
133 |
//Display MCE button name
|
sl@41
|
134 |
//labelButtonName.Text = e.MceButton.ToString();
|
sl@5
|
135 |
//Check if this is an HP extension
|
StephaneLenclud@66
|
136 |
if (Enum.IsDefined(typeof(Hid.Usage.HpWindowsMediaCenterRemoteControl), (ushort)e.MceButton))
|
sl@5
|
137 |
{
|
sl@5
|
138 |
//Also display HP button name
|
sl@41
|
139 |
//labelButtonName.Text += " / HP:" + ((Hid.UsageTables.HpWindowsMediaCenterRemoteControl)e.MceButton).ToString();
|
sl@6
|
140 |
}
|
sl@19
|
141 |
|
sl@40
|
142 |
processed = true;
|
sl@19
|
143 |
}
|
StephaneLenclud@66
|
144 |
else if (e.ConsumerControl != Hid.Usage.ConsumerControl.Null)
|
sl@19
|
145 |
{
|
sl@19
|
146 |
//Display consumer control name
|
sl@41
|
147 |
//labelButtonName.Text = e.ConsumerControl.ToString();
|
sl@19
|
148 |
processed = true;
|
sl@3
|
149 |
}
|
sl@3
|
150 |
else
|
sl@3
|
151 |
{
|
sl@41
|
152 |
//labelButtonName.Text = "Unknown";
|
sl@3
|
153 |
}
|
sl@41
|
154 |
//labelDeviceName.Text = e.Device.ToString();
|
sl@0
|
155 |
_timer.Enabled = true;
|
sl@19
|
156 |
return processed;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
private void _timer_Tick(object sender, EventArgs e)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
_timer.Enabled = false;
|
sl@38
|
162 |
labelButtonName.Text = "Ready...";
|
sl@0
|
163 |
}
|
sl@38
|
164 |
|
StephaneLenclud@49
|
165 |
private void buttonClear_Click(object sender, EventArgs e)
|
StephaneLenclud@49
|
166 |
{
|
StephaneLenclud@49
|
167 |
listViewEvents.Items.Clear();
|
StephaneLenclud@49
|
168 |
}
|
StephaneLenclud@49
|
169 |
|
StephaneLenclud@65
|
170 |
private void buttonTreeViewCollapseAll_Click(object sender, EventArgs e)
|
StephaneLenclud@65
|
171 |
{
|
StephaneLenclud@65
|
172 |
treeViewDevices.CollapseAll();
|
StephaneLenclud@65
|
173 |
}
|
StephaneLenclud@65
|
174 |
|
StephaneLenclud@65
|
175 |
private void buttonTreeViewExpandAll_Click(object sender, EventArgs e)
|
StephaneLenclud@65
|
176 |
{
|
StephaneLenclud@65
|
177 |
treeViewDevices.ExpandAll();
|
StephaneLenclud@65
|
178 |
}
|
StephaneLenclud@65
|
179 |
|
StephaneLenclud@72
|
180 |
private void buttonRefresh_Click(object sender, EventArgs e)
|
StephaneLenclud@72
|
181 |
{
|
StephaneLenclud@72
|
182 |
treeViewDevices.Nodes.Clear();
|
StephaneLenclud@72
|
183 |
Win32.RawInput.PopulateDeviceList(treeViewDevices);
|
StephaneLenclud@72
|
184 |
}
|
StephaneLenclud@72
|
185 |
|
sl@0
|
186 |
}
|
sl@0
|
187 |
}
|