Adding HidP_GetUsageValue function declaration.
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());
107 toolStripStatusLabelDevice.Text = aHidEvent.Device.FriendlyName;
111 protected override void WndProc(ref Message message)
115 _remote.ProcessMessage(message);
117 base.WndProc(ref message);
120 private bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
122 //Set text from here was disabled because of threading issues
123 //That whole thing should be removed anyway
124 bool processed = false;
125 _timer.Enabled = false;
126 if (e.Button != RemoteControlButton.Unknown)
128 //labelButtonName.Text = e.Button.ToString();
131 else if (e.MceButton != Hid.Usage.WindowsMediaCenterRemoteControl.Null)
133 //Display MCE button name
134 //labelButtonName.Text = e.MceButton.ToString();
135 //Check if this is an HP extension
136 if (Enum.IsDefined(typeof(Hid.Usage.HpWindowsMediaCenterRemoteControl), (ushort)e.MceButton))
138 //Also display HP button name
139 //labelButtonName.Text += " / HP:" + ((Hid.UsageTables.HpWindowsMediaCenterRemoteControl)e.MceButton).ToString();
144 else if (e.ConsumerControl != Hid.Usage.ConsumerControl.Null)
146 //Display consumer control name
147 //labelButtonName.Text = e.ConsumerControl.ToString();
152 //labelButtonName.Text = "Unknown";
154 //labelDeviceName.Text = e.Device.ToString();
155 _timer.Enabled = true;
159 private void _timer_Tick(object sender, EventArgs e)
161 _timer.Enabled = false;
162 labelButtonName.Text = "Ready...";
165 private void buttonClear_Click(object sender, EventArgs e)
167 listViewEvents.Items.Clear();
170 private void buttonTreeViewCollapseAll_Click(object sender, EventArgs e)
172 treeViewDevices.CollapseAll();
175 private void buttonTreeViewExpandAll_Click(object sender, EventArgs e)
177 treeViewDevices.ExpandAll();