Moving files around.
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;
34 /// Summary description for Form1.
36 public partial class MainForm : System.Windows.Forms.Form
38 private HidHandler iHidHandler;
40 public delegate void OnHidEventDelegate(object aSender, SharpLib.Hid.HidEvent 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 RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[6];
75 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl;
76 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl;
77 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
78 rid[i].hwndTarget = Handle;
81 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer;
82 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.ConsumerControl;
83 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
84 rid[i].hwndTarget = Handle;
87 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer;
88 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.Selection;
89 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
90 rid[i].hwndTarget = Handle;
93 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
94 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.SystemControl;
95 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
96 rid[i].hwndTarget = Handle;
99 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
100 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.GamePad;
101 rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
102 rid[i].hwndTarget = Handle;
105 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
106 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.Keyboard;
107 //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
108 rid[i].hwndTarget = Handle;
111 //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls;
112 //rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse;
113 //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
114 //rid[i].hwndTarget = aHWND;
117 iHidHandler = new SharpLib.Hid.HidHandler(rid);
118 if (!iHidHandler.IsRegistered)
120 Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString());
122 iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
125 public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.HidEvent aHidEvent)
127 if (aHidEvent.IsStray)
129 //Stray event just ignore it
133 if (this.InvokeRequired)
135 //Not in the proper thread, invoke ourselves
136 OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe);
137 this.Invoke(d, new object[] { aSender, aHidEvent });
141 //We are in the proper thread
142 listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem());
143 toolStripStatusLabelDevice.Text = aHidEvent.Device.FriendlyName;
147 protected override void WndProc(ref Message message)
151 case Const.WM_KEYDOWN:
152 //ProcessKeyDown(message.WParam);
155 //Returning zero means we processed that message.
156 message.Result = new IntPtr(0);
157 iHidHandler.ProcessInput(ref message);
160 //Is that needed? Check the docs.
161 base.WndProc(ref message);
164 private void buttonClear_Click(object sender, EventArgs e)
166 listViewEvents.Items.Clear();
169 private void buttonTreeViewCollapseAll_Click(object sender, EventArgs e)
171 treeViewDevices.CollapseAll();
174 private void buttonTreeViewExpandAll_Click(object sender, EventArgs e)
176 treeViewDevices.ExpandAll();
179 private void buttonRefresh_Click(object sender, EventArgs e)
181 treeViewDevices.Nodes.Clear();
182 SharpLib.Win32.RawInput.PopulateDeviceList(treeViewDevices);