Adding missing source file.
Updating SharpLibHid.
Now Green Start works better when app in background.
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
6 using System.Diagnostics;
7 using System.Runtime.InteropServices;
8 using System.Windows.Forms;
10 using Hid = SharpLib.Hid;
13 namespace SharpDisplayManager
15 [System.ComponentModel.DesignerCategory("Code")]
16 public partial class MainForm: Form
18 public delegate void OnHidEventDelegate(object aSender, Hid.Event aHidEvent);
21 /// Use notably to handle green start key from IR remote control
23 private Hid.Handler iHidHandler;
25 void RegisterHidDevices()
27 // Register the input device to receive the commands from the
28 // remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp
29 // for the vendor defined usage page.
31 RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[5];
34 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl;
35 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl;
36 rid[i].dwFlags = Const.RIDEV_INPUTSINK;
37 rid[i].hwndTarget = Handle;
40 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer;
41 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.ConsumerControl;
42 rid[i].dwFlags = Const.RIDEV_INPUTSINK;
43 rid[i].hwndTarget = Handle;
46 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer;
47 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.Selection;
48 rid[i].dwFlags = Const.RIDEV_INPUTSINK;
49 rid[i].hwndTarget = Handle;
52 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
53 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.SystemControl;
54 rid[i].dwFlags = Const.RIDEV_INPUTSINK;
55 rid[i].hwndTarget = Handle;
58 rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
59 rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.GamePad;
60 rid[i].dwFlags = Const.RIDEV_INPUTSINK;
61 rid[i].hwndTarget = Handle;
64 //rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
65 //rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.Keyboard;
66 //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
67 //rid[i].hwndTarget = Handle;
70 //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls;
71 //rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse;
72 //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
73 //rid[i].hwndTarget = aHWND;
76 iHidHandler = new SharpLib.Hid.Handler(rid);
77 if (!iHidHandler.IsRegistered)
79 Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString());
81 iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
84 public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent)
86 if (aHidEvent.IsStray)
88 //Stray event just ignore it
92 if (this.InvokeRequired)
94 //Not in the proper thread, invoke ourselves
95 OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe);
96 this.Invoke(d, new object[] { aSender, aHidEvent });
100 //We are in the proper thread
101 //listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem());
102 //toolStripStatusLabelDevice.Text = aHidEvent.Device.FriendlyName;
104 if (aHidEvent.Usages.Count > 0
105 && aHidEvent.UsagePage == (ushort)Hid.UsagePage.WindowsMediaCenterRemoteControl
106 && aHidEvent.Usages[0] == (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.GreenStart)
108 //Hard coding it all for now
109 // Prepare the process to run
110 ProcessStartInfo start = new ProcessStartInfo();
111 // Enter in the command line arguments, everything you would enter after the executable name itself
112 //start.Arguments = arguments;
113 // Enter the executable to run, including the complete path
114 start.FileName = "C:\\Program Files (x86)\\Team MediaPortal\\MediaPortal\\MediaPortal.exe";
115 // Do you want to show a console window?
116 start.WindowStyle = ProcessWindowStyle.Hidden;
117 start.CreateNoWindow = true;
118 // Run the external process & wait for it to finish
119 Process proc = Process.Start(start);
124 protected override void WndProc(ref Message message)
129 //Returning zero means we processed that message.
130 message.Result = new IntPtr(0);
131 iHidHandler.ProcessInput(ref message);
134 //Is that needed? Check the docs.
135 base.WndProc(ref message);