# HG changeset patch # User sl # Date 1417823999 -3600 # Node ID d066e3999973569bbf15bc22ef729339448640b8 # Parent 24ac84ab96204261e75ee68a2432b64f95ef6d4e Starting to remove special case for app commands. Adding a whole bunch of consumer controls. diff -r 24ac84ab9620 -r d066e3999973 Form1.cs --- a/Form1.cs Fri Dec 05 23:18:13 2014 +0100 +++ b/Form1.cs Sat Dec 06 00:59:59 2014 +0100 @@ -122,12 +122,14 @@ base.WndProc(ref message); } - private void _remote_ButtonPressed(object sender, RemoteControlEventArgs e) + private bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e) { + bool processed = false; _timer.Enabled = false; if (e.Button != RemoteControlButton.Unknown) { label1.Text = e.Button.ToString(); + processed = true; } else if (e.MceButton != Hid.UsageTables.MceButton.Null) { @@ -139,6 +141,14 @@ //Also display HP button name label1.Text += " / HP:" + ((Hid.UsageTables.HpMceButton)e.MceButton).ToString(); } + + processed = true; + } + else if (e.ConsumerControl != Hid.UsageTables.ConsumerControl.Null) + { + //Display consumer control name + label1.Text = e.ConsumerControl.ToString(); + processed = true; } else { @@ -146,6 +156,7 @@ } label2.Text = e.Device.ToString(); _timer.Enabled = true; + return processed; } private void _timer_Tick(object sender, EventArgs e) diff -r 24ac84ab9620 -r d066e3999973 HumanInterfaceDevice.cs --- a/HumanInterfaceDevice.cs Fri Dec 05 23:18:13 2014 +0100 +++ b/HumanInterfaceDevice.cs Sat Dec 06 00:59:59 2014 +0100 @@ -246,18 +246,129 @@ /// public enum ConsumerControl: ushort { + Null = 0x0000, + // + Channel = 0x0086, + MediaSelection = 0x0087, + MediaSelectComputer = 0x0088, + MediaSelectTV = 0x0089, + MediaSelectWWW = 0x008A, + MediaSelectDVD = 0x008B, + MediaSelectTelephone = 0x008C, + MediaSelectProgramGuide = 0x008D, + MediaSelectVideoPhone = 0x008E, + MediaSelectGames = 0x008F, + MediaSelectMessages = 0x0090, + MediaSelectCD = 0x0091, + MediaSelectVCR = 0x0092, + MediaSelectTuner = 0x0093, + Quit = 0x0094, + Help = 0x0095, + MediaSelectTape = 0x0096, + MediaSelectCable = 0x0097, + MediaSelectSatellite = 0x0098, + MediaSelectSecurity = 0x0099, + MediaSelectHome = 0x009A, + MediaSelectCall = 0x009B, + ChannelIncrement = 0x009C, + ChannelDecrement = 0x009D, + MediaSelectSAP = 0x009E, + // + Play = 0x00B0, + Pause = 0x00B1, + Record = 0x00B2, + FastForward = 0x00B3, + Rewind = 0x00B4, + ScanNextTrack = 0x00B5, + ScanPreviousTrack = 0x00B6, + Stop = 0x00B7, + Eject = 0x00B8, + RandomPlay = 0x00B9, + SelectDisc = 0x00BA, + EnterDisc = 0x00BB, + Repeat = 0x00BC, + Tracking = 0x00BD, + TrackNormal = 0x00BE, + SlowTracking = 0x00BF, + FrameForward = 0x00C0, + FrameBack = 0x00C1, + Mark = 0x00C2, + ClearMark = 0x00C3, + RepeatFromMark = 0x00C4, + ReturnToMark = 0x00C5, + SearchMarkForward = 0x00C6, + SearchMarkBackwards = 0x00C7, + CounterReset = 0x00C8, + ShowCounter = 0x00C9, + TrackingIncrement = 0x00CA, + TrackingDecrement = 0x00CB, + StopEject = 0x00CC, + PlayPause = 0x00CD, + PlaySkip = 0x00CE, + /// - /// Sent by MCE remotes. + /// Audio controls /// - MediaSelectProgramGuide = 0x008D, - /// - /// Sent by MCE remotes. - /// + Volume = 0x00E0, + Balance = 0x00E1, + Mute = 0x00E2, + Bass = 0x00E3, + Treble = 0x00E4, + BassBoost = 0x00E5, + SurroundMode = 0x00E6, + Loudness = 0x00E7, + MPX = 0x00E8, + VolumeIncrement = 0x00E9, + VolumeDecrement = 0x00EA, + + //Generic GUI Application Controls + GenericGUIApplicationControls = 0x0200, + AppCtrlNew = 0x0201, + AppCtrlOpen = 0x0202, + AppCtrlClose = 0x0203, + AppCtrlExit = 0x0204, + AppCtrlMaximize = 0x0205, + AppCtrlMinimize = 0x0206, + AppCtrlSave = 0x0207, AppCtrlPrint = 0x0208, - /// - /// Sent by MCE remotes from the 'I' Informations or More Info buttons. - /// - AppCtrlProperties = 0x0209 + AppCtrlProperties = 0x0209, + AppCtrlUndo = 0x021A, + AppCtrlCopy = 0x021B, + AppCtrlCut = 0x021C, + AppCtrlPaste = 0x021D, + AppCtrlSelectAll = 0x021E, + AppCtrlFind = 0x021F, + AppCtrlFindAndReplace = 0x0220, + AppCtrlSearch = 0x0221, + AppCtrlGoTo = 0x0222, + AppCtrlHome = 0x0223, + AppCtrlBack = 0x0224, + AppCtrlForward = 0x0225, + AppCtrlStop = 0x0226, + AppCtrlRefresh = 0x0227, + AppCtrlPreviousLink = 0x0228, + AppCtrlNextLink = 0x0229, + AppCtrlBookmarks = 0x022A, + AppCtrlHistory = 0x022B, + AppCtrlSubscriptions = 0x022C, + AppCtrlZoomIn = 0x022D, + AppCtrlZoomOut = 0x022E, + AppCtrlZoom = 0x022F, + AppCtrlFullScreenView = 0x0230, + AppCtrlNormalView = 0x0231, + AppCtrlViewToggle = 0x0232, + AppCtrlScrollUp = 0x0233, + AppCtrlScrollDown = 0x0234, + AppCtrlScroll = 0x0235, + AppCtrlPanLeft = 0x0236, + AppCtrlPanRight = 0x0237, + AppCtrlPan = 0x0238, + AppCtrlNewWindow = 0x0239, + AppCtrlTileHorizontally = 0x023A, + AppCtrlTileVertically = 0x023B, + AppCtrlFormat = 0x023C, + AppCtrlEdit = 0x023D, + } } } \ No newline at end of file diff -r 24ac84ab9620 -r d066e3999973 RawInput.cs --- a/RawInput.cs Fri Dec 05 23:18:13 2014 +0100 +++ b/RawInput.cs Sat Dec 06 00:59:59 2014 +0100 @@ -94,7 +94,7 @@ } /// - /// + /// Fetch pre-parsed data corresponding to HID descriptor for the given HID device. /// /// /// @@ -118,120 +118,6 @@ return ppData; } - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /* - private bool GetUsageFromRawInput(TwinhanHidDriver driver, TwinhanHid device, NativeMethods.RAWINPUT input, IntPtr rawInput, out UsageType usageType, out int usage, out string usageName) - { - usageType = 0; - usage = 0; - usageName = string.Empty; - if (input.header.dwType == NativeMethods.RawInputDeviceType.RIM_TYPEKEYBOARD) - { - if (input.data.keyboard.Flags == NativeMethods.RawInputKeyboardFlag.RI_KEY_BREAK) - { - _modifiers = 0; - // Key up event. We don't handle repeats, so ignore this. - return false; - } - NativeMethods.VirtualKey vk = input.data.keyboard.VKey; - if (vk == NativeMethods.VirtualKey.VK_CONTROL) - { - _modifiers |= VirtualKeyModifier.Control; - return false; - } - if (vk == NativeMethods.VirtualKey.VK_SHIFT) - { - _modifiers |= VirtualKeyModifier.Shift; - return false; - } - if (vk == NativeMethods.VirtualKey.VK_MENU) - { - _modifiers |= VirtualKeyModifier.Alt; - return false; - } - usageType = UsageType.Keyboard; - usage = (int)vk | (int)_modifiers; - usageName = vk.ToString(); - if (_modifiers != 0) - { - usageName += string.Format(", modifiers = {0}", _modifiers); - } - } - else if (input.header.dwType == NativeMethods.RawInputDeviceType.RIM_TYPEHID) - { - if ((!driver.IsTerraTec && device.Name.Contains("Col03")) || (driver.IsTerraTec && device.Name.Contains("Col02"))) - { - usageType = UsageType.Raw; - usage = Marshal.ReadByte(rawInput, HID_INPUT_DATA_OFFSET + 1); - usageName = string.Format("0x{0:x2}", usage); - } - else if (device.Name.Contains("Col05")) - { - usageType = UsageType.Ascii; - usage = Marshal.ReadByte(rawInput, HID_INPUT_DATA_OFFSET + 1); - usageName = string.Format("0x{0:x2}", usage); - } - else - { - byte[] report = new byte[input.data.hid.dwSizeHid]; - Marshal.Copy(IntPtr.Add(rawInput, HID_INPUT_DATA_OFFSET), report, 0, report.Length); - uint usageCount = input.data.hid.dwCount; - NativeMethods.USAGE_AND_PAGE[] usages = new NativeMethods.USAGE_AND_PAGE[usageCount]; - NativeMethods.HidStatus status = NativeMethods.HidP_GetUsagesEx(NativeMethods.HIDP_REPORT_TYPE.HidP_Input, 0, usages, ref usageCount, device.PreParsedData, report, (uint)report.Length); - if (status != NativeMethods.HidStatus.HIDP_STATUS_SUCCESS) - { - this.LogError("Twinhan HID remote: failed to get raw input HID usages, device = {0}, status = {1}", device.Name, status); - Dump.DumpBinary(rawInput, (int)input.header.dwSize); - return false; - } - if (usageCount > 1) - { - this.LogWarn("Twinhan HID remote: multiple simultaneous HID usages not supported"); - } - NativeMethods.USAGE_AND_PAGE up = usages[0]; - HidUsagePage page = (HidUsagePage)up.UsagePage; - usage = up.Usage; - if (page != HidUsagePage.MceRemote && usage == 0) - { - // Key up event. We don't handle repeats, so ignore this. - return false; - } - if (page == HidUsagePage.Consumer) - { - usageType = UsageType.Consumer; - usageName = Enum.GetName(typeof(HidConsumerUsage), up.Usage); - } - else if (page == HidUsagePage.MceRemote) - { - usageType = UsageType.Mce; - usageName = Enum.GetName(typeof(MceRemoteUsage), up.Usage); - } - else - { - this.LogError("Twinhan HID remote: unexpected usage page, device = {0}, page = {1}, usage = {2}", device.Name, page, up.Usage); - return false; - } - } - } - else - { - this.LogError("Twinhan HID remote: received input from unsupported input device type, device = {0}, type = {1}", device.Name, input.header.dwType); - return false; - } - return true; - } - * */ } } \ No newline at end of file diff -r 24ac84ab9620 -r d066e3999973 RemoteControlDevice.cs --- a/RemoteControlDevice.cs Fri Dec 05 23:18:13 2014 +0100 +++ b/RemoteControlDevice.cs Sat Dec 06 00:59:59 2014 +0100 @@ -80,19 +80,38 @@ RemoteControlButton _rcb; InputDevice _device; MceButton iMceButton; + ConsumerControl iConsumerControl; public RemoteControlEventArgs(RemoteControlButton rcb, InputDevice device) { - iMceButton = MceButton.Null; + SetNullButtons(); + // _rcb = rcb; - _device = device; + _device = device; } + public RemoteControlEventArgs(ConsumerControl aConsumerControl, InputDevice device) + { + SetNullButtons(); + // + iConsumerControl = aConsumerControl; + _device = device; + } + + public RemoteControlEventArgs(MceButton mce, InputDevice device) { - iMceButton = mce; + SetNullButtons(); + // + iMceButton = mce; + _device = device; + } + + private void SetNullButtons() + { + iConsumerControl = ConsumerControl.Null; + iMceButton = MceButton.Null; _rcb = RemoteControlButton.Unknown; - _device = device; } public RemoteControlEventArgs() @@ -114,6 +133,12 @@ set { iMceButton = value; } } + public ConsumerControl ConsumerControl + { + get { return iConsumerControl; } + set { iConsumerControl = value; } + } + public InputDevice Device { get { return _device; } @@ -126,10 +151,15 @@ public sealed class RemoteControlDevice { - public delegate void RemoteControlDeviceEventHandler(object sender, RemoteControlEventArgs e); + public delegate bool RemoteControlDeviceEventHandler(object sender, RemoteControlEventArgs e); public event RemoteControlDeviceEventHandler ButtonPressed; - public delegate void HidUsageHandler(ushort aUsage); + /// + /// Return true if the usage was processed. + /// + /// + /// + public delegate bool HidUsageHandler(ushort aUsage); //------------------------------------------------------------- @@ -178,11 +208,12 @@ ProcessKeyDown(message.WParam); break; case Const.WM_APPCOMMAND: - ProcessAppCommand(message.LParam); + //ProcessAppCommand(message.LParam); break; case Const.WM_INPUT: + //Returning zero means we processed that message. + message.Result = new IntPtr(0); ProcessInputCommand(ref message); - message.Result = new IntPtr(0); break; } @@ -318,37 +349,26 @@ /// /// /// - private void HidConsumerDeviceHandler(ushort aUsage) + private bool HidConsumerDeviceHandler(ushort aUsage) { if (aUsage == 0) { //Just skip those - return; + return false; } if (Enum.IsDefined(typeof(ConsumerControl), aUsage) && aUsage != 0) //Our button is a known consumer control { if (this.ButtonPressed != null) { - RemoteControlButton button=RemoteControlButton.Unknown; - if (aUsage == (ushort)ConsumerControl.AppCtrlProperties) - { - button = RemoteControlButton.MoreInfo; - } - else if (aUsage == (ushort)ConsumerControl.AppCtrlPrint) - { - button = RemoteControlButton.Print; - } - else if (aUsage == (ushort)ConsumerControl.MediaSelectProgramGuide) - { - button = RemoteControlButton.Guide; - } - this.ButtonPressed(this, new RemoteControlEventArgs(button, InputDevice.OEM)); + return this.ButtonPressed(this, new RemoteControlEventArgs((ConsumerControl)aUsage, InputDevice.OEM)); } + return false; } else { Debug.WriteLine("Unknown Consumer Control!"); + return false; } } @@ -356,12 +376,12 @@ /// /// /// - private void HidMceRemoteHandler(ushort aUsage) + private bool HidMceRemoteHandler(ushort aUsage) { if (aUsage == 0) { //Just skip those - return; + return false; } @@ -369,14 +389,15 @@ { if (this.ButtonPressed != null) { - this.ButtonPressed(this, new RemoteControlEventArgs((MceButton)aUsage, InputDevice.OEM)); + return this.ButtonPressed(this, new RemoteControlEventArgs((MceButton)aUsage, InputDevice.OEM)); } + return false; } else { Debug.WriteLine("Unknown MCE button!"); + return false; } - }