Proper support for all MCE buttons.
1.1 --- a/Form1.cs Tue Nov 04 19:49:34 2014 +0100
1.2 +++ b/Form1.cs Tue Nov 04 20:58:19 2014 +0100
1.3 @@ -123,7 +123,18 @@
1.4 private void _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
1.5 {
1.6 _timer.Enabled = false;
1.7 - label1.Text = e.Button.ToString();
1.8 + if (e.Button != RemoteControlButton.Unknown)
1.9 + {
1.10 + label1.Text = e.Button.ToString();
1.11 + }
1.12 + else if (e.MceButton != MceButton.Null)
1.13 + {
1.14 + label1.Text = e.MceButton.ToString();
1.15 + }
1.16 + else
1.17 + {
1.18 + label1.Text = "Unknown";
1.19 + }
1.20 label2.Text = e.Device.ToString();
1.21 _timer.Enabled = true;
1.22 }
2.1 --- a/RemoteControlDevice.cs Tue Nov 04 19:49:34 2014 +0100
2.2 +++ b/RemoteControlDevice.cs Tue Nov 04 20:58:19 2014 +0100
2.3 @@ -69,34 +69,101 @@
2.4 Unknown
2.5 }
2.6
2.7 + /// <summary>
2.8 + ///
2.9 + /// </summary>
2.10 + public enum MceButton
2.11 + {
2.12 + Null = 0x00, //Not defined by the specs
2.13 + GreenStart = 0x0D,
2.14 + ClosedCaptioning = 0x2B,
2.15 + Teletext = 0x5A,
2.16 + TeletextRed = 0x5B,
2.17 + TeletextGreen = 0x5C,
2.18 + TeletextYellow = 0x5D,
2.19 + TeletextBlue = 0x5E,
2.20 + LiveTv = 0x25,
2.21 + Music = 0x47,
2.22 + RecordedTv = 0x48,
2.23 + Pictures = 0x49,
2.24 + Videos = 0x4A,
2.25 + FmRadio = 0x50,
2.26 + Extras = 0x3C,
2.27 + ExtrasApp = 0x3D,
2.28 + DvdMenu = 0x24,
2.29 + DvdAngle = 0x4B,
2.30 + DvdAudio = 0x4C,
2.31 + DvdSubtitle = 0x4D,
2.32 + Eject = 0x28,
2.33 + DvdTopMenu = 0x43,
2.34 + Ext0 = 0x32,
2.35 + Ext1 = 0x33,
2.36 + Ext2 = 0x34,
2.37 + Ext3 = 0x35,
2.38 + Ext4 = 0x36,
2.39 + Ext5 = 0x37,
2.40 + Ext6 = 0x38,
2.41 + Ext7 = 0x39,
2.42 + Ext8 = 0x3A,
2.43 + Ext9 = 0x80,
2.44 + Ext10 = 0x81,
2.45 + Ext11 = 0x6F,
2.46 + Zoom = 0x27,
2.47 + ChannelInput = 0x42,
2.48 + SubAudio = 0x2D,
2.49 + Channel10 = 0x3E,
2.50 + Channel11 = 0x3F,
2.51 + Channel12 = 0x40,
2.52 + Display = 0x4F,
2.53 + Kiosk = 0x6A,
2.54 + NetworkSelection = 0x2C,
2.55 + BlueRayTool = 0x78,
2.56 + ChannelInfo = 0x41,
2.57 + VideoSelection = 0x61
2.58 + }
2.59 +
2.60
2.61 #region RemoteControlEventArgs
2.62
2.63 public class RemoteControlEventArgs : EventArgs
2.64 {
2.65 - RemoteControlButton _rcb;
2.66 + RemoteControlButton _rcb;
2.67 InputDevice _device;
2.68 + MceButton iMceButton;
2.69
2.70 - public RemoteControlEventArgs(RemoteControlButton rcb, InputDevice device)
2.71 + public RemoteControlEventArgs(RemoteControlButton rcb, InputDevice device)
2.72 {
2.73 + iMceButton = MceButton.Null;
2.74 _rcb = rcb;
2.75 _device = device;
2.76 }
2.77
2.78 + public RemoteControlEventArgs(MceButton mce, InputDevice device)
2.79 + {
2.80 + iMceButton = mce;
2.81 + _rcb = RemoteControlButton.Unknown;
2.82 + _device = device;
2.83 + }
2.84
2.85 public RemoteControlEventArgs()
2.86 {
2.87 + iMceButton = MceButton.Null;
2.88 _rcb = RemoteControlButton.Unknown;
2.89 _device = InputDevice.Key;
2.90 }
2.91
2.92 -
2.93 public RemoteControlButton Button
2.94 {
2.95 get { return _rcb; }
2.96 set { _rcb = value; }
2.97 }
2.98
2.99 + public MceButton MceButton
2.100 + {
2.101 + get { return iMceButton; }
2.102 + set { iMceButton = value; }
2.103 + }
2.104 +
2.105 public InputDevice Device
2.106 {
2.107 get { return _device; }
2.108 @@ -231,22 +298,6 @@
2.109 private const int APPCOMMAND_MEDIA_CHANNEL_UP = 51;
2.110 private const int APPCOMMAND_MEDIA_CHANNEL_DOWN = 52;
2.111
2.112 - private const int RAWINPUT_DETAILS = 0x209;
2.113 - private const int RAWINPUT_GUIDE = 0x8D;
2.114 - private const int RAWINPUT_TVJUMP = 0x25;
2.115 - private const int RAWINPUT_STANDBY = 0x82;
2.116 - private const int RAWINPUT_OEM1 = 0x80;
2.117 - private const int RAWINPUT_OEM2 = 0x81;
2.118 - private const int RAWINPUT_MYTV = 0x46;
2.119 - private const int RAWINPUT_MYVIDEOS = 0x4A;
2.120 - private const int RAWINPUT_MYPICTURES = 0x49;
2.121 - private const int RAWINPUT_MYMUSIC = 0x47;
2.122 - private const int RAWINPUT_RECORDEDTV = 0x48;
2.123 - private const int RAWINPUT_DVDANGLE = 0x4B;
2.124 - private const int RAWINPUT_DVDAUDIO = 0x4C;
2.125 - private const int RAWINPUT_DVDMENU = 0x24;
2.126 - private const int RAWINPUT_DVDSUBTITLE = 0x4D;
2.127 -
2.128 private const int RIM_TYPEMOUSE = 0;
2.129 private const int RIM_TYPEKEYBOARD = 1;
2.130 private const int RIM_TYPEHID = 2;
2.131 @@ -498,57 +549,13 @@
2.132 int rawData = bRawData[1]; //Get button code
2.133 Debug.WriteLine("HID " + raw.hid.dwCount + "/" + raw.hid.dwSizeHid + ":" + bRawData[0].ToString("X2") + bRawData[1].ToString("X2"));
2.134
2.135 - switch (rawData)
2.136 - {
2.137 - case RAWINPUT_DETAILS:
2.138 - rcb = RemoteControlButton.Details;
2.139 - break;
2.140 - case RAWINPUT_GUIDE:
2.141 - rcb = RemoteControlButton.Guide;
2.142 - break;
2.143 - case RAWINPUT_TVJUMP:
2.144 - rcb = RemoteControlButton.TVJump;
2.145 - break;
2.146 - case RAWINPUT_STANDBY:
2.147 - rcb = RemoteControlButton.StandBy;
2.148 - break;
2.149 - case RAWINPUT_OEM1:
2.150 - rcb = RemoteControlButton.OEM1;
2.151 - break;
2.152 - case RAWINPUT_OEM2:
2.153 - rcb = RemoteControlButton.OEM2;
2.154 - break;
2.155 - case RAWINPUT_MYTV:
2.156 - rcb = RemoteControlButton.MyTV;
2.157 - break;
2.158 - case RAWINPUT_MYVIDEOS:
2.159 - rcb = RemoteControlButton.MyVideos;
2.160 - break;
2.161 - case RAWINPUT_MYPICTURES:
2.162 - rcb = RemoteControlButton.MyPictures;
2.163 - break;
2.164 - case RAWINPUT_MYMUSIC:
2.165 - rcb = RemoteControlButton.MyMusic;
2.166 - break;
2.167 - case RAWINPUT_RECORDEDTV:
2.168 - rcb = RemoteControlButton.RecordedTV;
2.169 - break;
2.170 - case RAWINPUT_DVDANGLE:
2.171 - rcb = RemoteControlButton.DVDAngle;
2.172 - break;
2.173 - case RAWINPUT_DVDAUDIO:
2.174 - rcb = RemoteControlButton.DVDAudio;
2.175 - break;
2.176 - case RAWINPUT_DVDMENU:
2.177 - rcb = RemoteControlButton.DVDMenu;
2.178 - break;
2.179 - case RAWINPUT_DVDSUBTITLE:
2.180 - rcb = RemoteControlButton.DVDSubtitle;
2.181 - break;
2.182 - }
2.183 -
2.184 - if (rcb != RemoteControlButton.Unknown && this.ButtonPressed != null)
2.185 - this.ButtonPressed(this, new RemoteControlEventArgs(rcb, GetDevice(message.LParam.ToInt32())));
2.186 + if (Enum.IsDefined(typeof(MceButton), rawData) && rawData!=0) //Our button is a known MCE button
2.187 + {
2.188 + if (this.ButtonPressed != null) //What's that?
2.189 + {
2.190 + this.ButtonPressed(this, new RemoteControlEventArgs((MceButton)rawData, GetDevice(message.LParam.ToInt32())));
2.191 + }
2.192 + }
2.193 }
2.194 else if(raw.header.dwType == RIM_TYPEMOUSE)
2.195 {