Starting to remove special case for app commands.
authorsl
Sat, 06 Dec 2014 00:59:59 +0100
changeset 19d066e3999973
parent 18 24ac84ab9620
child 20 f2b65a8318e9
Starting to remove special case for app commands.
Adding a whole bunch of consumer controls.
Form1.cs
HumanInterfaceDevice.cs
RawInput.cs
RemoteControlDevice.cs
     1.1 --- a/Form1.cs	Fri Dec 05 23:18:13 2014 +0100
     1.2 +++ b/Form1.cs	Sat Dec 06 00:59:59 2014 +0100
     1.3 @@ -122,12 +122,14 @@
     1.4  			base.WndProc(ref message);
     1.5  		}
     1.6  
     1.7 -		private void _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
     1.8 +		private bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
     1.9  		{
    1.10 +            bool processed = false;
    1.11  			_timer.Enabled = false;
    1.12              if (e.Button != RemoteControlButton.Unknown)
    1.13              {
    1.14                  label1.Text = e.Button.ToString();
    1.15 +                processed = true;
    1.16              }
    1.17              else if (e.MceButton != Hid.UsageTables.MceButton.Null)
    1.18              {
    1.19 @@ -139,6 +141,14 @@
    1.20                      //Also display HP button name
    1.21                      label1.Text += " / HP:" + ((Hid.UsageTables.HpMceButton)e.MceButton).ToString();
    1.22                  }
    1.23 +
    1.24 +                processed = true;
    1.25 +            }
    1.26 +            else if (e.ConsumerControl != Hid.UsageTables.ConsumerControl.Null)
    1.27 +            {
    1.28 +                //Display consumer control name
    1.29 +                label1.Text = e.ConsumerControl.ToString();
    1.30 +                processed = true;
    1.31              }
    1.32              else
    1.33              {
    1.34 @@ -146,6 +156,7 @@
    1.35              }
    1.36  			label2.Text = e.Device.ToString();
    1.37  			_timer.Enabled = true;
    1.38 +            return processed;
    1.39  		}
    1.40  
    1.41  		private void _timer_Tick(object sender, EventArgs e)
     2.1 --- a/HumanInterfaceDevice.cs	Fri Dec 05 23:18:13 2014 +0100
     2.2 +++ b/HumanInterfaceDevice.cs	Sat Dec 06 00:59:59 2014 +0100
     2.3 @@ -246,18 +246,129 @@
     2.4          /// </summary>
     2.5          public enum ConsumerControl: ushort
     2.6          {
     2.7 +            Null = 0x0000,           
     2.8 +            //           
     2.9 +            Channel = 0x0086,
    2.10 +            MediaSelection = 0x0087,
    2.11 +            MediaSelectComputer = 0x0088,
    2.12 +            MediaSelectTV = 0x0089,
    2.13 +            MediaSelectWWW = 0x008A,
    2.14 +            MediaSelectDVD = 0x008B,
    2.15 +            MediaSelectTelephone = 0x008C,
    2.16 +            MediaSelectProgramGuide = 0x008D,
    2.17 +            MediaSelectVideoPhone = 0x008E,
    2.18 +            MediaSelectGames = 0x008F,
    2.19 +            MediaSelectMessages = 0x0090,
    2.20 +            MediaSelectCD = 0x0091,
    2.21 +            MediaSelectVCR = 0x0092,
    2.22 +            MediaSelectTuner = 0x0093,
    2.23 +            Quit = 0x0094,
    2.24 +            Help = 0x0095,
    2.25 +            MediaSelectTape = 0x0096,
    2.26 +            MediaSelectCable = 0x0097,
    2.27 +            MediaSelectSatellite = 0x0098,
    2.28 +            MediaSelectSecurity = 0x0099,
    2.29 +            MediaSelectHome = 0x009A,
    2.30 +            MediaSelectCall = 0x009B,
    2.31 +            ChannelIncrement = 0x009C,
    2.32 +            ChannelDecrement = 0x009D,
    2.33 +            MediaSelectSAP = 0x009E,
    2.34 +            //
    2.35 +            Play = 0x00B0,
    2.36 +            Pause = 0x00B1,
    2.37 +            Record = 0x00B2,
    2.38 +            FastForward = 0x00B3,
    2.39 +            Rewind = 0x00B4,
    2.40 +            ScanNextTrack = 0x00B5,
    2.41 +            ScanPreviousTrack = 0x00B6,
    2.42 +            Stop = 0x00B7,
    2.43 +            Eject = 0x00B8,
    2.44 +            RandomPlay = 0x00B9,
    2.45 +            SelectDisc = 0x00BA,
    2.46 +            EnterDisc = 0x00BB,
    2.47 +            Repeat = 0x00BC,
    2.48 +            Tracking = 0x00BD,
    2.49 +            TrackNormal = 0x00BE,
    2.50 +            SlowTracking = 0x00BF,
    2.51 +            FrameForward = 0x00C0,
    2.52 +            FrameBack = 0x00C1,
    2.53 +            Mark = 0x00C2,
    2.54 +            ClearMark = 0x00C3,
    2.55 +            RepeatFromMark = 0x00C4,
    2.56 +            ReturnToMark = 0x00C5,
    2.57 +            SearchMarkForward = 0x00C6,
    2.58 +            SearchMarkBackwards = 0x00C7,
    2.59 +            CounterReset = 0x00C8,
    2.60 +            ShowCounter = 0x00C9,
    2.61 +            TrackingIncrement = 0x00CA,
    2.62 +            TrackingDecrement = 0x00CB,
    2.63 +            StopEject = 0x00CC,
    2.64 +            PlayPause = 0x00CD,
    2.65 +            PlaySkip = 0x00CE,
    2.66 +
    2.67              /// <summary>
    2.68 -            /// Sent by MCE remotes.
    2.69 +            /// Audio controls
    2.70              /// </summary>
    2.71 -            MediaSelectProgramGuide = 0x008D,
    2.72 -            /// <summary>
    2.73 -            /// Sent by MCE remotes.
    2.74 -            /// </summary>
    2.75 +            Volume = 0x00E0,
    2.76 +            Balance = 0x00E1,
    2.77 +            Mute = 0x00E2,
    2.78 +            Bass = 0x00E3,
    2.79 +            Treble = 0x00E4,
    2.80 +            BassBoost = 0x00E5,
    2.81 +            SurroundMode = 0x00E6,
    2.82 +            Loudness = 0x00E7,
    2.83 +            MPX = 0x00E8,
    2.84 +            VolumeIncrement = 0x00E9,
    2.85 +            VolumeDecrement = 0x00EA,
    2.86 +
    2.87 +            //Generic GUI Application Controls
    2.88 +            GenericGUIApplicationControls = 0x0200,
    2.89 +            AppCtrlNew = 0x0201,
    2.90 +            AppCtrlOpen = 0x0202,
    2.91 +            AppCtrlClose = 0x0203,
    2.92 +            AppCtrlExit = 0x0204,
    2.93 +            AppCtrlMaximize = 0x0205,
    2.94 +            AppCtrlMinimize = 0x0206,
    2.95 +            AppCtrlSave = 0x0207,
    2.96              AppCtrlPrint = 0x0208,
    2.97 -            /// <summary>
    2.98 -            /// Sent by MCE remotes from the 'I' Informations or More Info buttons.
    2.99 -            /// </summary>
   2.100 -            AppCtrlProperties = 0x0209            
   2.101 +            AppCtrlProperties = 0x0209,
   2.102 +            AppCtrlUndo = 0x021A,
   2.103 +            AppCtrlCopy = 0x021B,
   2.104 +            AppCtrlCut = 0x021C,
   2.105 +            AppCtrlPaste = 0x021D,
   2.106 +            AppCtrlSelectAll = 0x021E,
   2.107 +            AppCtrlFind = 0x021F,
   2.108 +            AppCtrlFindAndReplace = 0x0220,
   2.109 +            AppCtrlSearch = 0x0221,
   2.110 +            AppCtrlGoTo = 0x0222,
   2.111 +            AppCtrlHome = 0x0223,
   2.112 +            AppCtrlBack = 0x0224,
   2.113 +            AppCtrlForward = 0x0225,
   2.114 +            AppCtrlStop = 0x0226,
   2.115 +            AppCtrlRefresh = 0x0227,
   2.116 +            AppCtrlPreviousLink = 0x0228,
   2.117 +            AppCtrlNextLink = 0x0229,
   2.118 +            AppCtrlBookmarks = 0x022A,
   2.119 +            AppCtrlHistory = 0x022B,
   2.120 +            AppCtrlSubscriptions = 0x022C,
   2.121 +            AppCtrlZoomIn = 0x022D,
   2.122 +            AppCtrlZoomOut = 0x022E,
   2.123 +            AppCtrlZoom = 0x022F,
   2.124 +            AppCtrlFullScreenView = 0x0230,
   2.125 +            AppCtrlNormalView = 0x0231,
   2.126 +            AppCtrlViewToggle = 0x0232,
   2.127 +            AppCtrlScrollUp = 0x0233,
   2.128 +            AppCtrlScrollDown = 0x0234,
   2.129 +            AppCtrlScroll = 0x0235,
   2.130 +            AppCtrlPanLeft = 0x0236,
   2.131 +            AppCtrlPanRight = 0x0237,
   2.132 +            AppCtrlPan = 0x0238,
   2.133 +            AppCtrlNewWindow = 0x0239,
   2.134 +            AppCtrlTileHorizontally = 0x023A,
   2.135 +            AppCtrlTileVertically = 0x023B,
   2.136 +            AppCtrlFormat = 0x023C,
   2.137 +            AppCtrlEdit = 0x023D,
   2.138 +
   2.139          }
   2.140      }
   2.141  }
   2.142 \ No newline at end of file
     3.1 --- a/RawInput.cs	Fri Dec 05 23:18:13 2014 +0100
     3.2 +++ b/RawInput.cs	Sat Dec 06 00:59:59 2014 +0100
     3.3 @@ -94,7 +94,7 @@
     3.4          }
     3.5  
     3.6          /// <summary>
     3.7 -        /// 
     3.8 +        /// Fetch pre-parsed data corresponding to HID descriptor for the given HID device.
     3.9          /// </summary>
    3.10          /// <param name="device"></param>
    3.11          /// <returns></returns>
    3.12 @@ -118,120 +118,6 @@
    3.13              return ppData;
    3.14          }
    3.15  
    3.16 -        /// <summary>
    3.17 -        /// 
    3.18 -        /// </summary>
    3.19 -        /// <param name="driver"></param>
    3.20 -        /// <param name="device"></param>
    3.21 -        /// <param name="input"></param>
    3.22 -        /// <param name="rawInput"></param>
    3.23 -        /// <param name="usageType"></param>
    3.24 -        /// <param name="usage"></param>
    3.25 -        /// <param name="usageName"></param>
    3.26 -        /// <returns></returns>
    3.27 -        /// 
    3.28 -        /*
    3.29 -        private bool GetUsageFromRawInput(TwinhanHidDriver driver, TwinhanHid device, NativeMethods.RAWINPUT input, IntPtr rawInput, out UsageType usageType, out int usage, out string usageName)
    3.30 -        {
    3.31 -            usageType = 0;
    3.32 -            usage = 0;
    3.33 -            usageName = string.Empty;
    3.34 -            if (input.header.dwType == NativeMethods.RawInputDeviceType.RIM_TYPEKEYBOARD)
    3.35 -            {
    3.36 -                if (input.data.keyboard.Flags == NativeMethods.RawInputKeyboardFlag.RI_KEY_BREAK)
    3.37 -                {
    3.38 -                    _modifiers = 0;
    3.39 -                    // Key up event. We don't handle repeats, so ignore this.
    3.40 -                    return false;
    3.41 -                }
    3.42 -                NativeMethods.VirtualKey vk = input.data.keyboard.VKey;
    3.43 -                if (vk == NativeMethods.VirtualKey.VK_CONTROL)
    3.44 -                {
    3.45 -                    _modifiers |= VirtualKeyModifier.Control;
    3.46 -                    return false;
    3.47 -                }
    3.48 -                if (vk == NativeMethods.VirtualKey.VK_SHIFT)
    3.49 -                {
    3.50 -                    _modifiers |= VirtualKeyModifier.Shift;
    3.51 -                    return false;
    3.52 -                }
    3.53 -                if (vk == NativeMethods.VirtualKey.VK_MENU)
    3.54 -                {
    3.55 -                    _modifiers |= VirtualKeyModifier.Alt;
    3.56 -                    return false;
    3.57 -                }
    3.58 -                usageType = UsageType.Keyboard;
    3.59 -                usage = (int)vk | (int)_modifiers;
    3.60 -                usageName = vk.ToString();
    3.61 -                if (_modifiers != 0)
    3.62 -                {
    3.63 -                    usageName += string.Format(", modifiers = {0}", _modifiers);
    3.64 -                }
    3.65 -            }
    3.66 -            else if (input.header.dwType == NativeMethods.RawInputDeviceType.RIM_TYPEHID)
    3.67 -            {
    3.68 -                if ((!driver.IsTerraTec && device.Name.Contains("Col03")) || (driver.IsTerraTec && device.Name.Contains("Col02")))
    3.69 -                {
    3.70 -                    usageType = UsageType.Raw;
    3.71 -                    usage = Marshal.ReadByte(rawInput, HID_INPUT_DATA_OFFSET + 1);
    3.72 -                    usageName = string.Format("0x{0:x2}", usage);
    3.73 -                }
    3.74 -                else if (device.Name.Contains("Col05"))
    3.75 -                {
    3.76 -                    usageType = UsageType.Ascii;
    3.77 -                    usage = Marshal.ReadByte(rawInput, HID_INPUT_DATA_OFFSET + 1);
    3.78 -                    usageName = string.Format("0x{0:x2}", usage);
    3.79 -                }
    3.80 -                else
    3.81 -                {
    3.82 -                    byte[] report = new byte[input.data.hid.dwSizeHid];
    3.83 -                    Marshal.Copy(IntPtr.Add(rawInput, HID_INPUT_DATA_OFFSET), report, 0, report.Length);
    3.84 -                    uint usageCount = input.data.hid.dwCount;
    3.85 -                    NativeMethods.USAGE_AND_PAGE[] usages = new NativeMethods.USAGE_AND_PAGE[usageCount];
    3.86 -                    NativeMethods.HidStatus status = NativeMethods.HidP_GetUsagesEx(NativeMethods.HIDP_REPORT_TYPE.HidP_Input, 0, usages, ref usageCount, device.PreParsedData, report, (uint)report.Length);
    3.87 -                    if (status != NativeMethods.HidStatus.HIDP_STATUS_SUCCESS)
    3.88 -                    {
    3.89 -                        this.LogError("Twinhan HID remote: failed to get raw input HID usages, device = {0}, status = {1}", device.Name, status);
    3.90 -                        Dump.DumpBinary(rawInput, (int)input.header.dwSize);
    3.91 -                        return false;
    3.92 -                    }
    3.93 -                    if (usageCount > 1)
    3.94 -                    {
    3.95 -                        this.LogWarn("Twinhan HID remote: multiple simultaneous HID usages not supported");
    3.96 -                    }
    3.97 -                    NativeMethods.USAGE_AND_PAGE up = usages[0];
    3.98 -                    HidUsagePage page = (HidUsagePage)up.UsagePage;
    3.99 -                    usage = up.Usage;
   3.100 -                    if (page != HidUsagePage.MceRemote && usage == 0)
   3.101 -                    {
   3.102 -                        // Key up event. We don't handle repeats, so ignore this.
   3.103 -                        return false;
   3.104 -                    }
   3.105 -                    if (page == HidUsagePage.Consumer)
   3.106 -                    {
   3.107 -                        usageType = UsageType.Consumer;
   3.108 -                        usageName = Enum.GetName(typeof(HidConsumerUsage), up.Usage);
   3.109 -                    }
   3.110 -                    else if (page == HidUsagePage.MceRemote)
   3.111 -                    {
   3.112 -                        usageType = UsageType.Mce;
   3.113 -                        usageName = Enum.GetName(typeof(MceRemoteUsage), up.Usage);
   3.114 -                    }
   3.115 -                    else
   3.116 -                    {
   3.117 -                        this.LogError("Twinhan HID remote: unexpected usage page, device = {0}, page = {1}, usage = {2}", device.Name, page, up.Usage);
   3.118 -                        return false;
   3.119 -                    }
   3.120 -                }
   3.121 -            }
   3.122 -            else
   3.123 -            {
   3.124 -                this.LogError("Twinhan HID remote: received input from unsupported input device type, device = {0}, type = {1}", device.Name, input.header.dwType);
   3.125 -                return false;
   3.126 -            }
   3.127 -            return true;
   3.128 -        }
   3.129 -         * */
   3.130  
   3.131      }
   3.132  }
   3.133 \ No newline at end of file
     4.1 --- a/RemoteControlDevice.cs	Fri Dec 05 23:18:13 2014 +0100
     4.2 +++ b/RemoteControlDevice.cs	Sat Dec 06 00:59:59 2014 +0100
     4.3 @@ -80,19 +80,38 @@
     4.4          RemoteControlButton _rcb;
     4.5  		InputDevice _device;
     4.6          MceButton iMceButton;
     4.7 +        ConsumerControl iConsumerControl;
     4.8  
     4.9          public RemoteControlEventArgs(RemoteControlButton rcb, InputDevice device)
    4.10  		{
    4.11 -            iMceButton = MceButton.Null;
    4.12 +            SetNullButtons();
    4.13 +            //
    4.14  			_rcb = rcb;
    4.15 -			_device = device;
    4.16 +			_device = device;            
    4.17  		}
    4.18  
    4.19 +        public RemoteControlEventArgs(ConsumerControl aConsumerControl, InputDevice device)
    4.20 +        {
    4.21 +            SetNullButtons();
    4.22 +            //
    4.23 +            iConsumerControl = aConsumerControl;            
    4.24 +            _device = device;
    4.25 +        }
    4.26 +
    4.27 +
    4.28          public RemoteControlEventArgs(MceButton mce, InputDevice device)
    4.29          {
    4.30 -            iMceButton = mce;
    4.31 +            SetNullButtons();
    4.32 +            //
    4.33 +            iMceButton = mce;            
    4.34 +            _device = device;
    4.35 +        }
    4.36 +
    4.37 +        private void SetNullButtons()
    4.38 +        {
    4.39 +            iConsumerControl = ConsumerControl.Null;
    4.40 +            iMceButton = MceButton.Null;
    4.41              _rcb = RemoteControlButton.Unknown;
    4.42 -            _device = device;
    4.43          }
    4.44  
    4.45  		public RemoteControlEventArgs()
    4.46 @@ -114,6 +133,12 @@
    4.47              set { iMceButton = value; }
    4.48          }
    4.49  
    4.50 +        public ConsumerControl ConsumerControl
    4.51 +        {
    4.52 +            get { return iConsumerControl; }
    4.53 +            set { iConsumerControl = value; }
    4.54 +        }
    4.55 +
    4.56  		public InputDevice Device
    4.57  		{
    4.58  			get { return _device;  }
    4.59 @@ -126,10 +151,15 @@
    4.60  
    4.61  	public sealed class RemoteControlDevice
    4.62  	{
    4.63 -		public delegate void RemoteControlDeviceEventHandler(object sender, RemoteControlEventArgs e);
    4.64 +		public delegate bool RemoteControlDeviceEventHandler(object sender, RemoteControlEventArgs e);
    4.65  		public event RemoteControlDeviceEventHandler ButtonPressed;
    4.66  
    4.67 -        public delegate void HidUsageHandler(ushort aUsage);
    4.68 +        /// <summary>
    4.69 +        /// Return true if the usage was processed.
    4.70 +        /// </summary>
    4.71 +        /// <param name="aUsage"></param>
    4.72 +        /// <returns></returns>
    4.73 +        public delegate bool HidUsageHandler(ushort aUsage);
    4.74          
    4.75  
    4.76  		//-------------------------------------------------------------
    4.77 @@ -178,11 +208,12 @@
    4.78                      ProcessKeyDown(message.WParam);
    4.79  					break;
    4.80                  case Const.WM_APPCOMMAND:
    4.81 -					ProcessAppCommand(message.LParam);
    4.82 +					//ProcessAppCommand(message.LParam);
    4.83  					break;
    4.84                  case Const.WM_INPUT:
    4.85 +                    //Returning zero means we processed that message.
    4.86 +                    message.Result = new IntPtr(0);
    4.87  					ProcessInputCommand(ref message);
    4.88 -                    message.Result = new IntPtr(0);
    4.89  					break;
    4.90  			}
    4.91  
    4.92 @@ -318,37 +349,26 @@
    4.93          /// 
    4.94          /// </summary>
    4.95          /// <param name="aUsage"></param>
    4.96 -        private void HidConsumerDeviceHandler(ushort aUsage)
    4.97 +        private bool HidConsumerDeviceHandler(ushort aUsage)
    4.98          {
    4.99              if (aUsage == 0)
   4.100              {
   4.101                  //Just skip those
   4.102 -                return;
   4.103 +                return false;
   4.104              }
   4.105  
   4.106              if (Enum.IsDefined(typeof(ConsumerControl), aUsage) && aUsage != 0) //Our button is a known consumer control
   4.107              {
   4.108                  if (this.ButtonPressed != null)
   4.109                  {
   4.110 -                    RemoteControlButton button=RemoteControlButton.Unknown;
   4.111 -                    if (aUsage == (ushort)ConsumerControl.AppCtrlProperties)
   4.112 -                    {
   4.113 -                        button = RemoteControlButton.MoreInfo;
   4.114 -                    }
   4.115 -                    else if (aUsage == (ushort)ConsumerControl.AppCtrlPrint)
   4.116 -                    {
   4.117 -                        button = RemoteControlButton.Print;
   4.118 -                    }
   4.119 -                    else if (aUsage == (ushort)ConsumerControl.MediaSelectProgramGuide)
   4.120 -                    {
   4.121 -                        button = RemoteControlButton.Guide;
   4.122 -                    }
   4.123 -                    this.ButtonPressed(this, new RemoteControlEventArgs(button, InputDevice.OEM));
   4.124 +                    return this.ButtonPressed(this, new RemoteControlEventArgs((ConsumerControl)aUsage, InputDevice.OEM));
   4.125                  }
   4.126 +                return false;
   4.127              }
   4.128              else
   4.129              {
   4.130                  Debug.WriteLine("Unknown Consumer Control!");
   4.131 +                return false;
   4.132              }
   4.133          }
   4.134  
   4.135 @@ -356,12 +376,12 @@
   4.136          /// 
   4.137          /// </summary>
   4.138          /// <param name="aUsage"></param>
   4.139 -        private void HidMceRemoteHandler(ushort aUsage)
   4.140 +        private bool HidMceRemoteHandler(ushort aUsage)
   4.141          {
   4.142              if (aUsage == 0)
   4.143              {
   4.144                  //Just skip those
   4.145 -                return;
   4.146 +                return false;
   4.147              }
   4.148  
   4.149  
   4.150 @@ -369,14 +389,15 @@
   4.151              {
   4.152                  if (this.ButtonPressed != null)
   4.153                  {
   4.154 -                    this.ButtonPressed(this, new RemoteControlEventArgs((MceButton)aUsage, InputDevice.OEM));
   4.155 +                    return this.ButtonPressed(this, new RemoteControlEventArgs((MceButton)aUsage, InputDevice.OEM));                    
   4.156                  }
   4.157 +                return false;
   4.158              }
   4.159              else
   4.160              {
   4.161                  Debug.WriteLine("Unknown MCE button!");
   4.162 +                return false;
   4.163              }
   4.164 -
   4.165          }
   4.166  
   4.167