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@0
|
14 |
public class Form1 : System.Windows.Forms.Form
|
sl@0
|
15 |
{
|
sl@0
|
16 |
/// <summary>
|
sl@0
|
17 |
/// Required designer variable.
|
sl@0
|
18 |
/// </summary>
|
sl@0
|
19 |
private System.ComponentModel.Container components = null;
|
sl@0
|
20 |
private System.Windows.Forms.Label label1;
|
sl@0
|
21 |
private RemoteControlDevice _remote;
|
sl@0
|
22 |
private System.Windows.Forms.Label label2;
|
sl@0
|
23 |
private Timer _timer;
|
sl@0
|
24 |
|
sl@0
|
25 |
public Form1()
|
sl@0
|
26 |
{
|
sl@0
|
27 |
//
|
sl@0
|
28 |
// Required for Windows Form Designer support
|
sl@0
|
29 |
//
|
sl@0
|
30 |
InitializeComponent();
|
sl@0
|
31 |
|
sl@0
|
32 |
_timer = new Timer();
|
sl@0
|
33 |
_timer.Interval = 3000;
|
sl@0
|
34 |
_timer.Enabled = false;
|
sl@15
|
35 |
_timer.Tick +=new EventHandler(_timer_Tick);
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
/// <summary>
|
sl@0
|
39 |
/// Clean up any resources being used.
|
sl@0
|
40 |
/// </summary>
|
sl@0
|
41 |
protected override void Dispose( bool disposing )
|
sl@0
|
42 |
{
|
sl@0
|
43 |
if( disposing )
|
sl@0
|
44 |
{
|
sl@6
|
45 |
if (components != null)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
components.Dispose();
|
sl@0
|
48 |
}
|
sl@0
|
49 |
}
|
sl@0
|
50 |
base.Dispose( disposing );
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
#region Windows Form Designer generated code
|
sl@0
|
54 |
/// <summary>
|
sl@0
|
55 |
/// Required method for Designer support - do not modify
|
sl@0
|
56 |
/// the contents of this method with the code editor.
|
sl@0
|
57 |
/// </summary>
|
sl@0
|
58 |
private void InitializeComponent()
|
sl@0
|
59 |
{
|
sl@0
|
60 |
this.label1 = new System.Windows.Forms.Label();
|
sl@0
|
61 |
this.label2 = new System.Windows.Forms.Label();
|
sl@0
|
62 |
this.SuspendLayout();
|
sl@6
|
63 |
//
|
sl@0
|
64 |
// label1
|
sl@6
|
65 |
//
|
sl@0
|
66 |
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
|
sl@0
|
67 |
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
|
sl@0
|
68 |
this.label1.ForeColor = System.Drawing.Color.White;
|
sl@0
|
69 |
this.label1.Location = new System.Drawing.Point(0, 0);
|
sl@0
|
70 |
this.label1.Name = "label1";
|
sl@0
|
71 |
this.label1.Size = new System.Drawing.Size(736, 266);
|
sl@0
|
72 |
this.label1.TabIndex = 0;
|
sl@0
|
73 |
this.label1.Text = "Ready...";
|
sl@0
|
74 |
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
sl@6
|
75 |
//
|
sl@0
|
76 |
// label2
|
sl@6
|
77 |
//
|
sl@0
|
78 |
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
|
sl@0
|
79 |
this.label2.Location = new System.Drawing.Point(72, 32);
|
sl@0
|
80 |
this.label2.Name = "label2";
|
sl@0
|
81 |
this.label2.Size = new System.Drawing.Size(576, 23);
|
sl@0
|
82 |
this.label2.TabIndex = 1;
|
sl@0
|
83 |
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
sl@6
|
84 |
//
|
sl@0
|
85 |
// Form1
|
sl@6
|
86 |
//
|
sl@0
|
87 |
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
|
sl@0
|
88 |
this.BackColor = System.Drawing.Color.LightSteelBlue;
|
sl@0
|
89 |
this.ClientSize = new System.Drawing.Size(736, 266);
|
sl@0
|
90 |
this.Controls.Add(this.label2);
|
sl@0
|
91 |
this.Controls.Add(this.label1);
|
sl@0
|
92 |
this.Name = "Form1";
|
sl@0
|
93 |
this.Text = "Remote Control Sample";
|
sl@0
|
94 |
this.Load += new System.EventHandler(this.Form1_Load);
|
sl@0
|
95 |
this.ResumeLayout(false);
|
sl@0
|
96 |
|
sl@0
|
97 |
}
|
sl@6
|
98 |
#endregion Windows Form Designer generated code
|
sl@0
|
99 |
|
sl@0
|
100 |
/// <summary>
|
sl@0
|
101 |
/// The main entry point for the application.
|
sl@0
|
102 |
/// </summary>
|
sl@0
|
103 |
[STAThread]
|
sl@6
|
104 |
static void Main()
|
sl@0
|
105 |
{
|
sl@0
|
106 |
Application.Run(new Form1());
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
private void Form1_Load(object sender, System.EventArgs e)
|
sl@0
|
110 |
{
|
sl@15
|
111 |
_remote = new RemoteControlDevice(this.Handle);
|
sl@15
|
112 |
_remote.ButtonPressed += new Devices.RemoteControl.RemoteControlDevice.RemoteControlDeviceEventHandler(_remote_ButtonPressed);
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
|
sl@0
|
116 |
protected override void WndProc(ref Message message)
|
sl@0
|
117 |
{
|
sl@15
|
118 |
if (_remote != null)
|
sl@15
|
119 |
{
|
sl@15
|
120 |
_remote.ProcessMessage(message);
|
sl@15
|
121 |
}
|
sl@0
|
122 |
base.WndProc(ref message);
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@19
|
125 |
private bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
|
sl@0
|
126 |
{
|
sl@19
|
127 |
bool processed = false;
|
sl@0
|
128 |
_timer.Enabled = false;
|
sl@3
|
129 |
if (e.Button != RemoteControlButton.Unknown)
|
sl@3
|
130 |
{
|
sl@3
|
131 |
label1.Text = e.Button.ToString();
|
sl@19
|
132 |
processed = true;
|
sl@3
|
133 |
}
|
sl@30
|
134 |
else if (e.MceButton != Hid.UsageTables.WindowsMediaCenterRemoteControl.Null)
|
sl@3
|
135 |
{
|
sl@5
|
136 |
//Display MCE button name
|
sl@3
|
137 |
label1.Text = e.MceButton.ToString();
|
sl@5
|
138 |
//Check if this is an HP extension
|
sl@9
|
139 |
if (Enum.IsDefined(typeof(Hid.UsageTables.HpMceButton), (ushort)e.MceButton))
|
sl@5
|
140 |
{
|
sl@5
|
141 |
//Also display HP button name
|
sl@8
|
142 |
label1.Text += " / HP:" + ((Hid.UsageTables.HpMceButton)e.MceButton).ToString();
|
sl@6
|
143 |
}
|
sl@19
|
144 |
|
sl@19
|
145 |
processed = true;
|
sl@19
|
146 |
}
|
sl@19
|
147 |
else if (e.ConsumerControl != Hid.UsageTables.ConsumerControl.Null)
|
sl@19
|
148 |
{
|
sl@19
|
149 |
//Display consumer control name
|
sl@19
|
150 |
label1.Text = e.ConsumerControl.ToString();
|
sl@19
|
151 |
processed = true;
|
sl@3
|
152 |
}
|
sl@3
|
153 |
else
|
sl@3
|
154 |
{
|
sl@3
|
155 |
label1.Text = "Unknown";
|
sl@3
|
156 |
}
|
sl@6
|
157 |
label2.Text = e.Device.ToString();
|
sl@0
|
158 |
_timer.Enabled = true;
|
sl@19
|
159 |
return processed;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
private void _timer_Tick(object sender, EventArgs e)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
_timer.Enabled = false;
|
sl@0
|
165 |
label1.Text = "Ready...";
|
sl@0
|
166 |
}
|
sl@0
|
167 |
}
|
sl@0
|
168 |
}
|