Adding missing public keyword for some of our usage enumerations.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of SharpLibHid.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
22 using System.Collections;
23 using System.ComponentModel;
24 using System.Windows.Forms;
26 using System.Diagnostics;
27 using System.Runtime.InteropServices;
28 using Hid = SharpLib.Hid;
34 /// MainForm for our HID demo.
36 public partial class MainForm : System.Windows.Forms.Form
38 private Hid.Handler iHidHandler;
40 public delegate void OnHidEventDelegate(object aSender, Hid.Event aHidEvent);
44 // Required for Windows Form Designer support
45 InitializeComponent();
50 /// The main entry point for the application.
55 Application.EnableVisualStyles();
56 Application.Run(new MainForm());
59 private void MainForm_Load(object sender, System.EventArgs e)
62 //Create our list of HID devices
63 SharpLib.Win32.RawInput.PopulateDeviceList(treeViewDevices);
66 void RegisterHidDevices()
68 // Register the input device to receive the commands from the
69 // remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp
70 // for the vendor defined usage page.
72 if (iHidHandler!=null)
75 iHidHandler.Dispose();
80 RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[5];
83 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl;
84 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl;
85 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
86 rid[i].hwndTarget = Handle;
89 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer;
90 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.ConsumerControl;
91 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
92 rid[i].hwndTarget = Handle;
95 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer;
96 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.Selection;
97 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
98 rid[i].hwndTarget = Handle;
101 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
102 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.SystemControl;
103 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
104 rid[i].hwndTarget = Handle;
107 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
108 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.GamePad;
109 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
110 rid[i].hwndTarget = Handle;
113 //rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
114 //rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.Keyboard;
115 //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
116 //rid[i].hwndTarget = Handle;
119 //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls;
120 //rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse;
121 //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
122 //rid[i].hwndTarget = aHWND;
125 iHidHandler = new SharpLib.Hid.Handler(rid, checkBoxRepeat.Checked);
126 if (!iHidHandler.IsRegistered)
128 Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString());
130 iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
133 public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent)
135 if (aHidEvent.IsStray)
137 //Stray event just ignore it
141 if (this.InvokeRequired)
143 //Not in the proper thread, invoke ourselves
144 OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe);
145 this.Invoke(d, new object[] { aSender, aHidEvent });
149 //We are in the proper thread
150 listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem());
151 toolStripStatusLabelDevice.Text = aHidEvent.Device.FriendlyName;
155 protected override void WndProc(ref Message message)
159 case Const.WM_KEYDOWN:
160 //ProcessKeyDown(message.WParam);
163 //Returning zero means we processed that message.
164 message.Result = new IntPtr(0);
165 iHidHandler.ProcessInput(ref message);
168 //Is that needed? Check the docs.
169 base.WndProc(ref message);
172 private void buttonClear_Click(object sender, EventArgs e)
174 listViewEvents.Items.Clear();
177 private void buttonTreeViewCollapseAll_Click(object sender, EventArgs e)
179 treeViewDevices.CollapseAll();
182 private void buttonTreeViewExpandAll_Click(object sender, EventArgs e)
184 treeViewDevices.ExpandAll();
187 private void buttonRefresh_Click(object sender, EventArgs e)
189 treeViewDevices.Nodes.Clear();
190 SharpLib.Win32.RawInput.PopulateDeviceList(treeViewDevices);
193 private void checkBoxRepeat_CheckedChanged(object sender, EventArgs e)
195 RegisterHidDevices();