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@0
|
23 |
private Timer _timer;
|
sl@0
|
24 |
|
sl@36
|
25 |
public MainForm()
|
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@38
|
60 |
this.labelButtonName = new System.Windows.Forms.Label();
|
sl@38
|
61 |
this.labelDeviceName = new System.Windows.Forms.Label();
|
sl@38
|
62 |
this.SuspendLayout();
|
sl@38
|
63 |
//
|
sl@38
|
64 |
// labelButtonName
|
sl@38
|
65 |
//
|
sl@38
|
66 |
this.labelButtonName.AutoSize = true;
|
sl@38
|
67 |
this.labelButtonName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
sl@38
|
68 |
this.labelButtonName.Location = new System.Drawing.Point(257, 97);
|
sl@38
|
69 |
this.labelButtonName.Name = "labelButtonName";
|
sl@38
|
70 |
this.labelButtonName.Size = new System.Drawing.Size(103, 20);
|
sl@38
|
71 |
this.labelButtonName.TabIndex = 0;
|
sl@38
|
72 |
this.labelButtonName.Text = "Button Name";
|
sl@38
|
73 |
//
|
sl@38
|
74 |
// labelDeviceName
|
sl@38
|
75 |
//
|
sl@38
|
76 |
this.labelDeviceName.AutoSize = true;
|
sl@38
|
77 |
this.labelDeviceName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
sl@38
|
78 |
this.labelDeviceName.Location = new System.Drawing.Point(257, 67);
|
sl@38
|
79 |
this.labelDeviceName.Name = "labelDeviceName";
|
sl@38
|
80 |
this.labelDeviceName.Size = new System.Drawing.Size(103, 20);
|
sl@38
|
81 |
this.labelDeviceName.TabIndex = 1;
|
sl@38
|
82 |
this.labelDeviceName.Text = "Device Name";
|
sl@38
|
83 |
//
|
sl@38
|
84 |
// MainForm
|
sl@38
|
85 |
//
|
sl@38
|
86 |
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
|
sl@38
|
87 |
this.BackColor = System.Drawing.SystemColors.Control;
|
sl@38
|
88 |
this.ClientSize = new System.Drawing.Size(784, 393);
|
sl@38
|
89 |
this.Controls.Add(this.labelDeviceName);
|
sl@38
|
90 |
this.Controls.Add(this.labelButtonName);
|
sl@38
|
91 |
this.Name = "MainForm";
|
sl@38
|
92 |
this.Text = "Remote Control Sample";
|
sl@38
|
93 |
this.Load += new System.EventHandler(this.Form1_Load);
|
sl@38
|
94 |
this.ResumeLayout(false);
|
sl@38
|
95 |
this.PerformLayout();
|
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@36
|
106 |
Application.Run(new MainForm());
|
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@38
|
131 |
labelButtonName.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@38
|
137 |
labelButtonName.Text = e.MceButton.ToString();
|
sl@5
|
138 |
//Check if this is an HP extension
|
sl@31
|
139 |
if (Enum.IsDefined(typeof(Hid.UsageTables.HpWindowsMediaCenterRemoteControl), (ushort)e.MceButton))
|
sl@5
|
140 |
{
|
sl@5
|
141 |
//Also display HP button name
|
sl@38
|
142 |
labelButtonName.Text += " / HP:" + ((Hid.UsageTables.HpWindowsMediaCenterRemoteControl)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@38
|
150 |
labelButtonName.Text = e.ConsumerControl.ToString();
|
sl@19
|
151 |
processed = true;
|
sl@3
|
152 |
}
|
sl@3
|
153 |
else
|
sl@3
|
154 |
{
|
sl@38
|
155 |
labelButtonName.Text = "Unknown";
|
sl@3
|
156 |
}
|
sl@38
|
157 |
labelDeviceName.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@38
|
165 |
labelButtonName.Text = "Ready...";
|
sl@0
|
166 |
}
|
sl@38
|
167 |
|
sl@0
|
168 |
}
|
sl@0
|
169 |
}
|