Adding input capabilities description to device list.
3 using System.Collections;
4 using System.ComponentModel;
5 using System.Windows.Forms;
7 using Devices.RemoteControl;
9 namespace RemoteControlSample
12 /// Summary description for Form1.
14 public partial class MainForm : System.Windows.Forms.Form
17 /// Required designer variable.
19 private System.ComponentModel.Container components = null;
20 private RemoteControlDevice _remote;
21 private Label labelButtonName;
22 private Label labelDeviceName;
23 private Button buttonClear;
24 private TabControl tabControl;
25 private TabPage tabPageMessages;
26 private ListView listViewEvents;
27 private ColumnHeader columnHeaderUsages;
28 private ColumnHeader columnHeaderInputReport;
29 private ColumnHeader columnHeaderUsagePage;
30 private ColumnHeader columnHeaderUsageCollection;
31 private ColumnHeader columnHeaderRepeat;
32 private ColumnHeader columnHeaderTime;
33 private TabPage tabPageDevices;
34 private TreeView treeViewDevices;
37 public delegate void OnHidEventDelegate(object aSender, Hid.HidEvent aHidEvent);
42 // Required for Windows Form Designer support
44 InitializeComponent();
47 _timer.Interval = 3000;
48 _timer.Enabled = false;
49 _timer.Tick +=new EventHandler(_timer_Tick);
53 /// Clean up any resources being used.
55 protected override void Dispose( bool disposing )
59 if (components != null)
64 base.Dispose( disposing );
69 /// The main entry point for the application.
74 Application.EnableVisualStyles();
75 Application.Run(new MainForm());
78 private void MainForm_Load(object sender, System.EventArgs e)
80 _remote = new RemoteControlDevice(this.Handle);
81 _remote.ButtonPressed += new Devices.RemoteControl.RemoteControlDevice.RemoteControlDeviceEventHandler(_remote_ButtonPressed);
82 _remote.iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
85 Win32.RawInput.PopulateDeviceList(treeViewDevices);
89 public void HandleHidEventThreadSafe(object aSender, Hid.HidEvent aHidEvent)
91 if (aHidEvent.IsStray)
93 //Stray event just ignore it
97 if (this.InvokeRequired)
99 //Not in the proper thread, invoke ourselves
100 OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe);
101 this.Invoke(d, new object[] { aSender, aHidEvent });
105 //We are in the proper thread
106 listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem());
110 protected override void WndProc(ref Message message)
114 _remote.ProcessMessage(message);
116 base.WndProc(ref message);
119 private bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
121 //Set text from here was disabled because of threading issues
122 //That whole thing should be removed anyway
123 bool processed = false;
124 _timer.Enabled = false;
125 if (e.Button != RemoteControlButton.Unknown)
127 //labelButtonName.Text = e.Button.ToString();
130 else if (e.MceButton != Hid.UsageTables.WindowsMediaCenterRemoteControl.Null)
132 //Display MCE button name
133 //labelButtonName.Text = e.MceButton.ToString();
134 //Check if this is an HP extension
135 if (Enum.IsDefined(typeof(Hid.UsageTables.HpWindowsMediaCenterRemoteControl), (ushort)e.MceButton))
137 //Also display HP button name
138 //labelButtonName.Text += " / HP:" + ((Hid.UsageTables.HpWindowsMediaCenterRemoteControl)e.MceButton).ToString();
143 else if (e.ConsumerControl != Hid.UsageTables.ConsumerControl.Null)
145 //Display consumer control name
146 //labelButtonName.Text = e.ConsumerControl.ToString();
151 //labelButtonName.Text = "Unknown";
153 //labelDeviceName.Text = e.Device.ToString();
154 _timer.Enabled = true;
158 private void _timer_Tick(object sender, EventArgs e)
160 _timer.Enabled = false;
161 labelButtonName.Text = "Ready...";
164 private void buttonClear_Click(object sender, EventArgs e)
166 listViewEvents.Items.Clear();