sl@0: using System; sl@0: using System.Drawing; sl@0: using System.Collections; sl@0: using System.ComponentModel; sl@0: using System.Windows.Forms; sl@0: using System.Data; sl@6: using Devices.RemoteControl; sl@0: sl@0: namespace RemoteControlSample sl@0: { sl@0: /// sl@0: /// Summary description for Form1. sl@0: /// StephaneLenclud@60: public partial class MainForm : System.Windows.Forms.Form sl@0: { sl@0: /// sl@0: /// Required designer variable. sl@0: /// sl@38: private System.ComponentModel.Container components = null; sl@38: private RemoteControlDevice _remote; sl@38: private Label labelButtonName; sl@38: private Label labelDeviceName; StephaneLenclud@60: private Button buttonClear; StephaneLenclud@60: private TabControl tabControl; StephaneLenclud@60: private TabPage tabPageMessages; sl@39: private ListView listViewEvents; StephaneLenclud@49: private ColumnHeader columnHeaderUsages; StephaneLenclud@60: private ColumnHeader columnHeaderInputReport; sl@40: private ColumnHeader columnHeaderUsagePage; sl@40: private ColumnHeader columnHeaderUsageCollection; sl@42: private ColumnHeader columnHeaderRepeat; sl@44: private ColumnHeader columnHeaderTime; StephaneLenclud@60: private TabPage tabPageDevices; StephaneLenclud@60: private TreeView treeViewDevices; sl@0: private Timer _timer; sl@0: sl@41: public delegate void OnHidEventDelegate(object aSender, Hid.HidEvent aHidEvent); sl@41: sl@36: public MainForm() sl@0: { sl@0: // sl@0: // Required for Windows Form Designer support sl@0: // sl@0: InitializeComponent(); sl@0: sl@0: _timer = new Timer(); sl@0: _timer.Interval = 3000; sl@0: _timer.Enabled = false; sl@15: _timer.Tick +=new EventHandler(_timer_Tick); sl@0: } sl@0: sl@0: /// sl@0: /// Clean up any resources being used. sl@0: /// sl@0: protected override void Dispose( bool disposing ) sl@0: { sl@0: if( disposing ) sl@0: { sl@6: if (components != null) sl@0: { sl@0: components.Dispose(); sl@0: } sl@0: } sl@0: base.Dispose( disposing ); sl@0: } sl@0: sl@0: sl@0: /// sl@0: /// The main entry point for the application. sl@0: /// sl@0: [STAThread] sl@6: static void Main() sl@0: { StephaneLenclud@60: Application.EnableVisualStyles(); sl@36: Application.Run(new MainForm()); sl@0: } sl@0: StephaneLenclud@60: private void MainForm_Load(object sender, System.EventArgs e) sl@0: { sl@15: _remote = new RemoteControlDevice(this.Handle); sl@15: _remote.ButtonPressed += new Devices.RemoteControl.RemoteControlDevice.RemoteControlDeviceEventHandler(_remote_ButtonPressed); StephaneLenclud@60: _remote.iHidHandler.OnHidEvent += HandleHidEventThreadSafe; StephaneLenclud@60: StephaneLenclud@60: // StephaneLenclud@60: Win32.RawInput.PopulateDeviceList(treeViewDevices); StephaneLenclud@60: sl@0: } sl@0: sl@41: public void HandleHidEventThreadSafe(object aSender, Hid.HidEvent aHidEvent) sl@40: { sl@42: if (aHidEvent.IsStray) sl@42: { sl@42: //Stray event just ignore it sl@42: return; sl@42: } sl@42: sl@41: if (this.InvokeRequired) sl@41: { sl@41: //Not in the proper thread, invoke ourselves sl@41: OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe); sl@41: this.Invoke(d, new object[] { aSender, aHidEvent }); sl@41: } sl@41: else sl@41: { sl@41: //We are in the proper thread sl@42: listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem()); sl@41: } sl@40: } sl@0: sl@0: protected override void WndProc(ref Message message) sl@0: { sl@15: if (_remote != null) sl@15: { sl@15: _remote.ProcessMessage(message); sl@15: } sl@0: base.WndProc(ref message); sl@0: } sl@0: sl@19: private bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e) sl@0: { sl@41: //Set text from here was disabled because of threading issues sl@41: //That whole thing should be removed anyway sl@19: bool processed = false; sl@0: _timer.Enabled = false; sl@3: if (e.Button != RemoteControlButton.Unknown) sl@3: { sl@41: //labelButtonName.Text = e.Button.ToString(); sl@19: processed = true; sl@3: } sl@30: else if (e.MceButton != Hid.UsageTables.WindowsMediaCenterRemoteControl.Null) sl@3: { sl@5: //Display MCE button name sl@41: //labelButtonName.Text = e.MceButton.ToString(); sl@5: //Check if this is an HP extension sl@31: if (Enum.IsDefined(typeof(Hid.UsageTables.HpWindowsMediaCenterRemoteControl), (ushort)e.MceButton)) sl@5: { sl@5: //Also display HP button name sl@41: //labelButtonName.Text += " / HP:" + ((Hid.UsageTables.HpWindowsMediaCenterRemoteControl)e.MceButton).ToString(); sl@6: } sl@19: sl@40: processed = true; sl@19: } sl@19: else if (e.ConsumerControl != Hid.UsageTables.ConsumerControl.Null) sl@19: { sl@19: //Display consumer control name sl@41: //labelButtonName.Text = e.ConsumerControl.ToString(); sl@19: processed = true; sl@3: } sl@3: else sl@3: { sl@41: //labelButtonName.Text = "Unknown"; sl@3: } sl@41: //labelDeviceName.Text = e.Device.ToString(); sl@0: _timer.Enabled = true; sl@19: return processed; sl@0: } sl@0: sl@0: private void _timer_Tick(object sender, EventArgs e) sl@0: { sl@0: _timer.Enabled = false; sl@38: labelButtonName.Text = "Ready..."; sl@0: } sl@38: StephaneLenclud@49: private void buttonClear_Click(object sender, EventArgs e) StephaneLenclud@49: { StephaneLenclud@49: listViewEvents.Items.Clear(); StephaneLenclud@49: } StephaneLenclud@49: sl@0: } sl@0: }