home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Code for MCE remote
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Anonymous" data-source="post: 6350"><p>Fond this code, havent tested it do I don't got my MCE remote yeat.</p><p></p><p>[code]</p><p></p><p>Imports System.Runtime.InteropServices</p><p></p><p>Public Enum MCERemoteButtons</p><p> Unknown</p><p> '-- WM_KEYDOWN type buttons (easy)</p><p> OK</p><p> MoveUp</p><p> MoveLeft</p><p> MoveRight</p><p> MoveDown</p><p> Back</p><p> Number1</p><p> Number2</p><p> Number3</p><p> Number4</p><p> Number5</p><p> Number6</p><p> Number7</p><p> Number8</p><p> Number9</p><p> Number0</p><p> Clear</p><p> Enter</p><p> '-- WM_APPCOMMAND type buttons</p><p> Pause</p><p> Play</p><p> Record</p><p> Replay</p><p> Rewind</p><p> Forward</p><p> Skip</p><p> ChannelDown</p><p> ChannelUp</p><p> [Stop]</p><p> '-- WM_INPUT (HID) type buttons</p><p> MoreInfo</p><p> DVDAngle</p><p> DVDAudio</p><p> DVDMenu</p><p> DVDSubtitle</p><p> Guide</p><p> Mute</p><p> MyTV</p><p> MyMusic</p><p> MyPictures</p><p> MyVideos</p><p> RecordedTV</p><p> OEM1</p><p> OEM2</p><p> LiveTV</p><p> VolumeDown</p><p> VolumeUp</p><p>End Enum</p><p></p><p>Public Class MCERemote</p><p> Inherits System.ComponentModel.Component</p><p></p><p>#Region " Windows Form Designer generated code "</p><p></p><p> Public Sub New(ByVal Container As System.ComponentModel.IContainer)</p><p> MyClass.New()</p><p> 'Required for Windows.Forms Class Composition Designer support</p><p> Container.Add(Me)</p><p> End Sub</p><p></p><p> Public Sub New()</p><p> MyBase.New()</p><p></p><p> 'This call is required by the Component Designer.</p><p> InitializeComponent()</p><p></p><p> 'Add any initialization after the InitializeComponent() call</p><p> End Sub</p><p></p><p> 'Component overrides dispose to clean up the component list.</p><p> Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)</p><p> If disposing Then</p><p> If Not (components Is Nothing) Then</p><p> components.Dispose()</p><p> End If</p><p> End If</p><p> MyBase.Dispose(disposing)</p><p> End Sub</p><p></p><p> 'Required by the Component Designer</p><p> Private components As System.ComponentModel.IContainer</p><p></p><p> 'NOTE: The following procedure is required by the Component Designer</p><p> 'It can be modified using the Component Designer.</p><p> 'Do not modify it using the code editor.</p><p> <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()</p><p> components = New System.ComponentModel.Container</p><p> End Sub</p><p></p><p>#End Region</p><p></p><p> Private Const WM_KEYDOWN As Integer = &H100</p><p> Private Const WM_APPCOMMAND As Integer = &H319</p><p> Private Const WM_INPUT As Integer = &HFF</p><p> Private Const RID_INPUT As Integer = &H10000003</p><p> Private Const RIM_TYPEMOUSE As Integer = 0</p><p> Private Const RIM_TYPEKEYBOARD As Integer = 1</p><p> Private Const RIM_TYPEHID As Integer = 2</p><p></p><p> Private _blnDebugMode As Boolean = True</p><p> Private _button As MCERemoteButtons</p><p> Private _intChar As Integer</p><p></p><p> Public Event ButtonPressed(ByVal Button As MCERemoteButtons)</p><p></p><p>#Region "Win32 API Declarations "</p><p></p><p> 'BOOL RegisterRawInputDevices {</p><p> ' PCRAWINPUTDEVICE pRawInputDevices,</p><p> ' UINT uiNumDevices,</p><p> ' UINT cbSize</p><p> ');</p><p> <DllImportAttribute("user32.dll")> _</p><p> Private Shared Function RegisterRawInputDevices _</p><p> (ByVal RIDs() As RAWINPUTDEVICE, _</p><p> ByVal uiNumDevices As Integer, _</p><p> ByVal cbSize As Integer) As Boolean</p><p> End Function</p><p></p><p> 'UINT GetRawInputData {</p><p> ' HRAWINPUT hRawInput,</p><p> ' UINT uiCommand,</p><p> ' LPVOID pData,</p><p> ' PUINT pcbSize,</p><p> ' UINT cbSizeHeader</p><p> '};</p><p> <DllImportAttribute("user32.dll")> _</p><p> Private Shared Function GetRawInputData _</p><p> (ByVal hRawInput As IntPtr, _</p><p> ByVal uiCommand As Integer, _</p><p> ByVal pData As IntPtr, _</p><p> ByRef byRefpcbSize As Integer, _</p><p> ByVal cbSizeHeader As Integer) As Integer</p><p> End Function</p><p></p><p> 'typedef struct tagRAWINPUTDEVICE {</p><p> ' USHORT usUsagePage;</p><p> ' USHORT usUsage;</p><p> ' DWORD dwFlags;</p><p> ' HWND hwndTarget;</p><p> '} RAWINPUTDEVICE, *PRAWINPUTDEVICE, *LPRAWINPUTDEVICE;</p><p> <StructLayout(LayoutKind.Sequential)> _</p><p> Private Structure RAWINPUTDEVICE</p><p> <MarshalAs(UnmanagedType.U2)> _</p><p> Public usUsagePage As Short</p><p> <MarshalAs(UnmanagedType.U2)> _</p><p> Public usUsage As Short</p><p> <MarshalAs(UnmanagedType.U4)> _</p><p> Public dwFlags As Integer</p><p> Public hwndTarget As IntPtr</p><p> End Structure</p><p></p><p> 'typedef struct tagRAWINPUT { </p><p> ' RAWINPUTHEADER header; </p><p> ' union {</p><p> ' RAWMOUSE mouse; </p><p> ' RAWKEYBOARD keyboard; </p><p> ' RAWHID hid; </p><p> ' } data;</p><p> '} RAWINPUT, *PRAWINPUT; *LPRAWINPUT;</p><p> Private Structure RAWINPUT</p><p> Dim header As RAWINPUTHEADER</p><p> Dim hid As RAWHID</p><p> End Structure</p><p></p><p> 'typedef struct tagRAWINPUTHEADER {</p><p> ' DWORD dwType;</p><p> ' DWORD dwSize;</p><p> ' HANDLE hDevice;</p><p> ' WPARAM wParam;</p><p> '} RAWINPUTHEADER, *PRAWINPUTHEADER;</p><p> <StructLayout(LayoutKind.Sequential)> _</p><p> Private Structure RAWINPUTHEADER</p><p> <MarshalAs(UnmanagedType.U4)> _</p><p> Dim dwType As Integer</p><p> <MarshalAs(UnmanagedType.U4)> _</p><p> Dim dwSize As Integer</p><p> Dim hDevice As IntPtr</p><p> <MarshalAs(UnmanagedType.U4)> _</p><p> Dim wParam As Integer</p><p> End Structure</p><p></p><p> 'typedef struct tagRAWHID {</p><p> ' DWORD dwSizeHid;</p><p> ' DWORD dwCount;</p><p> ' BYTE bRawData;</p><p> '} RAWHID, **LPRAWHID;</p><p> Private Structure RAWHID</p><p> Dim dwSizeHid As Integer</p><p> Dim dwCount As Integer</p><p> ' Followed by bRawData As Byte() (variable size)</p><p> End Structure</p><p></p><p>#End Region</p><p></p><p>#Region "Button Lookups"</p><p></p><p> Private Function LookupKey(ByVal intKeyCode As Integer) As MCERemoteButtons</p><p> Select Case intKeyCode</p><p> Case 9</p><p> Return MCERemoteButtons.Unknown</p><p> Case 13</p><p> Return MCERemoteButtons.OK</p><p> Case 27</p><p> Return MCERemoteButtons.Clear</p><p> Case 37</p><p> Return MCERemoteButtons.MoveLeft</p><p> Case 38</p><p> Return MCERemoteButtons.MoveUp</p><p> Case 39</p><p> Return MCERemoteButtons.MoveRight</p><p> Case 40</p><p> Return MCERemoteButtons.MoveDown</p><p> Case 48</p><p> Return MCERemoteButtons.Number0</p><p> Case 49</p><p> Return MCERemoteButtons.Number1</p><p> Case 50</p><p> Return MCERemoteButtons.Number2</p><p> Case 51</p><p> Return MCERemoteButtons.Number3</p><p> Case 52</p><p> Return MCERemoteButtons.Number4</p><p> Case 53</p><p> Return MCERemoteButtons.Number5</p><p> Case 54</p><p> Return MCERemoteButtons.Number6</p><p> Case 55</p><p> Return MCERemoteButtons.Number7</p><p> Case 56</p><p> Return MCERemoteButtons.Number8</p><p> Case 57</p><p> Return MCERemoteButtons.Number9</p><p> Case 58</p><p> Return MCERemoteButtons.Number0</p><p> Case Else</p><p> Debug.WriteLine("unknown keycode = " + intKeyCode.ToString)</p><p> Return MCERemoteButtons.Unknown</p><p> End Select</p><p> End Function</p><p></p><p> Private Function LookupAppCommand(ByVal intAppCode As Integer) As MCERemoteButtons</p><p> Select Case intAppCode</p><p> Case 65536</p><p> Return MCERemoteButtons.Back</p><p> Case 720896</p><p> Return MCERemoteButtons.Skip</p><p> Case 786432</p><p> Return MCERemoteButtons.Replay</p><p> Case 851968</p><p> Return MCERemoteButtons.[Stop]</p><p> Case 271450112</p><p> Return MCERemoteButtons.Play</p><p> Case 271515648</p><p> Return MCERemoteButtons.Pause</p><p> Case 271581184</p><p> Return MCERemoteButtons.Record</p><p> Case 271646720</p><p> Return MCERemoteButtons.Forward</p><p> Case 271712256</p><p> Return MCERemoteButtons.Rewind</p><p> Case 271777792</p><p> Return MCERemoteButtons.ChannelUp</p><p> Case 271843328</p><p> Return MCERemoteButtons.ChannelDown</p><p> Case Else</p><p> 'Debug.WriteLine("unknown appcommand " + intAppCode.ToString)</p><p> Return MCERemoteButtons.Unknown</p><p> End Select</p><p> End Function</p><p></p><p> Private Function LookupRaw(ByVal intRawByte1 As Byte, ByVal intRawByte2 As Byte) As MCERemoteButtons</p><p> Select Case intRawByte2</p><p> Case 9</p><p> Return MCERemoteButtons.MoreInfo</p><p> Case 36</p><p> If intRawByte1 = 1 Then</p><p> Return MCERemoteButtons.DVDMenu</p><p> Else</p><p> Return MCERemoteButtons.Unknown</p><p> End If</p><p> Case 37</p><p> Return MCERemoteButtons.LiveTV</p><p> Case 70</p><p> Return MCERemoteButtons.MyTV</p><p> Case 71</p><p> Return MCERemoteButtons.MyMusic</p><p> Case 72</p><p> Return MCERemoteButtons.RecordedTV</p><p> Case 73</p><p> Return MCERemoteButtons.MyPictures</p><p> Case 74</p><p> Return MCERemoteButtons.MyVideos</p><p> Case 75</p><p> Return MCERemoteButtons.DVDAngle</p><p> Case 76</p><p> Return MCERemoteButtons.DVDAudio</p><p> Case 77</p><p> Return MCERemoteButtons.DVDSubtitle</p><p> Case 128</p><p> Return MCERemoteButtons.OEM1</p><p> Case 129</p><p> Return MCERemoteButtons.OEM2</p><p> Case 141</p><p> Return MCERemoteButtons.Guide</p><p> Case 226</p><p> Return MCERemoteButtons.Mute</p><p> Case 233</p><p> Return MCERemoteButtons.VolumeUp</p><p> Case 234</p><p> Return MCERemoteButtons.VolumeDown</p><p> Case Else</p><p> 'If intRawByte2 > 0 Then</p><p> 'Debug.WriteLine("Unknown rawcode " + intRawByte1.ToString + ":" + intRawByte2.ToString)</p><p> 'End If</p><p> Return MCERemoteButtons.Unknown</p><p> End Select</p><p> End Function</p><p></p><p>#End Region</p><p></p><p> Public Sub Initialize(ByVal hWnd As IntPtr)</p><p></p><p> Dim objRID(1) As RAWINPUTDEVICE</p><p> '-- vendor-defined</p><p> objRID(0).usUsagePage = &HFFBCS</p><p> objRID(0).usUsage = &H88</p><p> objRID(0).dwFlags = 0</p><p> objRID(0).hwndTarget = hWnd</p><p> '-- consumer controls</p><p> objRID(1).usUsagePage = &HC</p><p> objRID(1).usUsage = &H1</p><p> objRID(1).dwFlags = 0</p><p> objRID(1).hwndTarget = hWnd</p><p> If RegisterRawInputDevices(objRID, objRID.Length, Marshal.SizeOf(objRID(0))) Then</p><p> Debug.WriteLine("raw input devices registered OK")</p><p> Else</p><p> Debug.WriteLine("Error registering raw input devices!")</p><p> End If</p><p></p><p> End Sub</p><p></p><p> Public Function WndProcHandler(ByRef m As System.Windows.Forms.Message) As Boolean</p><p></p><p> Select Case m.Msg</p><p> Case WM_KEYDOWN</p><p> _button = LookupKey(m.WParam.ToInt32)</p><p> If _button <> MCERemoteButtons.Unknown Then</p><p> RaiseEvent ButtonPressed(_button)</p><p> Return True</p><p> If _blnDebugMode Then</p><p> Debug.WriteLine("code " + m.WParam.ToString + " = key " + _button.ToString)</p><p> End If</p><p> End If</p><p></p><p> Case WM_APPCOMMAND</p><p> _button = LookupAppCommand(m.LParam.ToInt32)</p><p> If _button <> MCERemoteButtons.Unknown Then</p><p> RaiseEvent ButtonPressed(_button)</p><p> Return True</p><p> If _blnDebugMode Then</p><p> Debug.WriteLine("code " + m.LParam.ToString + " = app " + _button.ToString)</p><p> End If</p><p> End If</p><p></p><p> Case WM_INPUT</p><p> Dim pcbSize As Integer</p><p> '-- get the size of the data returned</p><p> GetRawInputData(m.LParam, RID_INPUT, IntPtr.Zero, pcbSize, Marshal.SizeOf(GetType(RAWINPUTHEADER)))</p><p> Dim buffer As IntPtr</p><p> Try</p><p> '-- copy the data to a buffer</p><p> buffer = Marshal.AllocHGlobal(pcbSize)</p><p> GetRawInputData(m.LParam, RID_INPUT, buffer, pcbSize, Marshal.SizeOf(GetType(RAWINPUTHEADER)))</p><p> '-- convert the buffer to header data structure</p><p> Dim raw As RAWINPUT</p><p> raw = CType(Marshal.PtrToStructure(buffer, GetType(RAWINPUT)), RAWINPUT)</p><p> If raw.header.dwType <> RIM_TYPEHID Then</p><p> Exit Try</p><p> End If</p><p> '-- get raw data to array of bytes</p><p> Dim bRawData(raw.hid.dwSizeHid - 1) As Byte</p><p> Dim pRawData As Integer</p><p> pRawData = buffer.ToInt32() + Marshal.SizeOf(GetType(RAWINPUT))</p><p> Marshal.Copy(New IntPtr(pRawData), bRawData, 0, raw.hid.dwSizeHid)</p><p> '-- look up button code from byte array</p><p> _button = LookupRaw(bRawData(0), bRawData(1))</p><p> If _button <> MCERemoteButtons.Unknown Then</p><p> RaiseEvent ButtonPressed(_button)</p><p> Return True</p><p> If _blnDebugMode Then</p><p> Debug.WriteLine("code " + bRawData(0).ToString + ":" + bRawData(1).ToString + " = " + _button.ToString)</p><p> End If</p><p> End If</p><p> Finally</p><p> If Not buffer.Equals(IntPtr.Zero) Then Marshal.FreeHGlobal(buffer)</p><p> End Try</p><p> End Select</p><p> Return False</p><p> End Function</p><p></p><p>End Class</p><p></p><p>[/code]</p></blockquote><p></p>
[QUOTE="Anonymous, post: 6350"] Fond this code, havent tested it do I don't got my MCE remote yeat. [code] Imports System.Runtime.InteropServices Public Enum MCERemoteButtons Unknown '-- WM_KEYDOWN type buttons (easy) OK MoveUp MoveLeft MoveRight MoveDown Back Number1 Number2 Number3 Number4 Number5 Number6 Number7 Number8 Number9 Number0 Clear Enter '-- WM_APPCOMMAND type buttons Pause Play Record Replay Rewind Forward Skip ChannelDown ChannelUp [Stop] '-- WM_INPUT (HID) type buttons MoreInfo DVDAngle DVDAudio DVDMenu DVDSubtitle Guide Mute MyTV MyMusic MyPictures MyVideos RecordedTV OEM1 OEM2 LiveTV VolumeDown VolumeUp End Enum Public Class MCERemote Inherits System.ComponentModel.Component #Region " Windows Form Designer generated code " Public Sub New(ByVal Container As System.ComponentModel.IContainer) MyClass.New() 'Required for Windows.Forms Class Composition Designer support Container.Add(Me) End Sub Public Sub New() MyBase.New() 'This call is required by the Component Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Component overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Component Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container End Sub #End Region Private Const WM_KEYDOWN As Integer = &H100 Private Const WM_APPCOMMAND As Integer = &H319 Private Const WM_INPUT As Integer = &HFF Private Const RID_INPUT As Integer = &H10000003 Private Const RIM_TYPEMOUSE As Integer = 0 Private Const RIM_TYPEKEYBOARD As Integer = 1 Private Const RIM_TYPEHID As Integer = 2 Private _blnDebugMode As Boolean = True Private _button As MCERemoteButtons Private _intChar As Integer Public Event ButtonPressed(ByVal Button As MCERemoteButtons) #Region "Win32 API Declarations " 'BOOL RegisterRawInputDevices { ' PCRAWINPUTDEVICE pRawInputDevices, ' UINT uiNumDevices, ' UINT cbSize '); <DllImportAttribute("user32.dll")> _ Private Shared Function RegisterRawInputDevices _ (ByVal RIDs() As RAWINPUTDEVICE, _ ByVal uiNumDevices As Integer, _ ByVal cbSize As Integer) As Boolean End Function 'UINT GetRawInputData { ' HRAWINPUT hRawInput, ' UINT uiCommand, ' LPVOID pData, ' PUINT pcbSize, ' UINT cbSizeHeader '}; <DllImportAttribute("user32.dll")> _ Private Shared Function GetRawInputData _ (ByVal hRawInput As IntPtr, _ ByVal uiCommand As Integer, _ ByVal pData As IntPtr, _ ByRef byRefpcbSize As Integer, _ ByVal cbSizeHeader As Integer) As Integer End Function 'typedef struct tagRAWINPUTDEVICE { ' USHORT usUsagePage; ' USHORT usUsage; ' DWORD dwFlags; ' HWND hwndTarget; '} RAWINPUTDEVICE, *PRAWINPUTDEVICE, *LPRAWINPUTDEVICE; <StructLayout(LayoutKind.Sequential)> _ Private Structure RAWINPUTDEVICE <MarshalAs(UnmanagedType.U2)> _ Public usUsagePage As Short <MarshalAs(UnmanagedType.U2)> _ Public usUsage As Short <MarshalAs(UnmanagedType.U4)> _ Public dwFlags As Integer Public hwndTarget As IntPtr End Structure 'typedef struct tagRAWINPUT { ' RAWINPUTHEADER header; ' union { ' RAWMOUSE mouse; ' RAWKEYBOARD keyboard; ' RAWHID hid; ' } data; '} RAWINPUT, *PRAWINPUT; *LPRAWINPUT; Private Structure RAWINPUT Dim header As RAWINPUTHEADER Dim hid As RAWHID End Structure 'typedef struct tagRAWINPUTHEADER { ' DWORD dwType; ' DWORD dwSize; ' HANDLE hDevice; ' WPARAM wParam; '} RAWINPUTHEADER, *PRAWINPUTHEADER; <StructLayout(LayoutKind.Sequential)> _ Private Structure RAWINPUTHEADER <MarshalAs(UnmanagedType.U4)> _ Dim dwType As Integer <MarshalAs(UnmanagedType.U4)> _ Dim dwSize As Integer Dim hDevice As IntPtr <MarshalAs(UnmanagedType.U4)> _ Dim wParam As Integer End Structure 'typedef struct tagRAWHID { ' DWORD dwSizeHid; ' DWORD dwCount; ' BYTE bRawData; '} RAWHID, **LPRAWHID; Private Structure RAWHID Dim dwSizeHid As Integer Dim dwCount As Integer ' Followed by bRawData As Byte() (variable size) End Structure #End Region #Region "Button Lookups" Private Function LookupKey(ByVal intKeyCode As Integer) As MCERemoteButtons Select Case intKeyCode Case 9 Return MCERemoteButtons.Unknown Case 13 Return MCERemoteButtons.OK Case 27 Return MCERemoteButtons.Clear Case 37 Return MCERemoteButtons.MoveLeft Case 38 Return MCERemoteButtons.MoveUp Case 39 Return MCERemoteButtons.MoveRight Case 40 Return MCERemoteButtons.MoveDown Case 48 Return MCERemoteButtons.Number0 Case 49 Return MCERemoteButtons.Number1 Case 50 Return MCERemoteButtons.Number2 Case 51 Return MCERemoteButtons.Number3 Case 52 Return MCERemoteButtons.Number4 Case 53 Return MCERemoteButtons.Number5 Case 54 Return MCERemoteButtons.Number6 Case 55 Return MCERemoteButtons.Number7 Case 56 Return MCERemoteButtons.Number8 Case 57 Return MCERemoteButtons.Number9 Case 58 Return MCERemoteButtons.Number0 Case Else Debug.WriteLine("unknown keycode = " + intKeyCode.ToString) Return MCERemoteButtons.Unknown End Select End Function Private Function LookupAppCommand(ByVal intAppCode As Integer) As MCERemoteButtons Select Case intAppCode Case 65536 Return MCERemoteButtons.Back Case 720896 Return MCERemoteButtons.Skip Case 786432 Return MCERemoteButtons.Replay Case 851968 Return MCERemoteButtons.[Stop] Case 271450112 Return MCERemoteButtons.Play Case 271515648 Return MCERemoteButtons.Pause Case 271581184 Return MCERemoteButtons.Record Case 271646720 Return MCERemoteButtons.Forward Case 271712256 Return MCERemoteButtons.Rewind Case 271777792 Return MCERemoteButtons.ChannelUp Case 271843328 Return MCERemoteButtons.ChannelDown Case Else 'Debug.WriteLine("unknown appcommand " + intAppCode.ToString) Return MCERemoteButtons.Unknown End Select End Function Private Function LookupRaw(ByVal intRawByte1 As Byte, ByVal intRawByte2 As Byte) As MCERemoteButtons Select Case intRawByte2 Case 9 Return MCERemoteButtons.MoreInfo Case 36 If intRawByte1 = 1 Then Return MCERemoteButtons.DVDMenu Else Return MCERemoteButtons.Unknown End If Case 37 Return MCERemoteButtons.LiveTV Case 70 Return MCERemoteButtons.MyTV Case 71 Return MCERemoteButtons.MyMusic Case 72 Return MCERemoteButtons.RecordedTV Case 73 Return MCERemoteButtons.MyPictures Case 74 Return MCERemoteButtons.MyVideos Case 75 Return MCERemoteButtons.DVDAngle Case 76 Return MCERemoteButtons.DVDAudio Case 77 Return MCERemoteButtons.DVDSubtitle Case 128 Return MCERemoteButtons.OEM1 Case 129 Return MCERemoteButtons.OEM2 Case 141 Return MCERemoteButtons.Guide Case 226 Return MCERemoteButtons.Mute Case 233 Return MCERemoteButtons.VolumeUp Case 234 Return MCERemoteButtons.VolumeDown Case Else 'If intRawByte2 > 0 Then 'Debug.WriteLine("Unknown rawcode " + intRawByte1.ToString + ":" + intRawByte2.ToString) 'End If Return MCERemoteButtons.Unknown End Select End Function #End Region Public Sub Initialize(ByVal hWnd As IntPtr) Dim objRID(1) As RAWINPUTDEVICE '-- vendor-defined objRID(0).usUsagePage = &HFFBCS objRID(0).usUsage = &H88 objRID(0).dwFlags = 0 objRID(0).hwndTarget = hWnd '-- consumer controls objRID(1).usUsagePage = &HC objRID(1).usUsage = &H1 objRID(1).dwFlags = 0 objRID(1).hwndTarget = hWnd If RegisterRawInputDevices(objRID, objRID.Length, Marshal.SizeOf(objRID(0))) Then Debug.WriteLine("raw input devices registered OK") Else Debug.WriteLine("Error registering raw input devices!") End If End Sub Public Function WndProcHandler(ByRef m As System.Windows.Forms.Message) As Boolean Select Case m.Msg Case WM_KEYDOWN _button = LookupKey(m.WParam.ToInt32) If _button <> MCERemoteButtons.Unknown Then RaiseEvent ButtonPressed(_button) Return True If _blnDebugMode Then Debug.WriteLine("code " + m.WParam.ToString + " = key " + _button.ToString) End If End If Case WM_APPCOMMAND _button = LookupAppCommand(m.LParam.ToInt32) If _button <> MCERemoteButtons.Unknown Then RaiseEvent ButtonPressed(_button) Return True If _blnDebugMode Then Debug.WriteLine("code " + m.LParam.ToString + " = app " + _button.ToString) End If End If Case WM_INPUT Dim pcbSize As Integer '-- get the size of the data returned GetRawInputData(m.LParam, RID_INPUT, IntPtr.Zero, pcbSize, Marshal.SizeOf(GetType(RAWINPUTHEADER))) Dim buffer As IntPtr Try '-- copy the data to a buffer buffer = Marshal.AllocHGlobal(pcbSize) GetRawInputData(m.LParam, RID_INPUT, buffer, pcbSize, Marshal.SizeOf(GetType(RAWINPUTHEADER))) '-- convert the buffer to header data structure Dim raw As RAWINPUT raw = CType(Marshal.PtrToStructure(buffer, GetType(RAWINPUT)), RAWINPUT) If raw.header.dwType <> RIM_TYPEHID Then Exit Try End If '-- get raw data to array of bytes Dim bRawData(raw.hid.dwSizeHid - 1) As Byte Dim pRawData As Integer pRawData = buffer.ToInt32() + Marshal.SizeOf(GetType(RAWINPUT)) Marshal.Copy(New IntPtr(pRawData), bRawData, 0, raw.hid.dwSizeHid) '-- look up button code from byte array _button = LookupRaw(bRawData(0), bRawData(1)) If _button <> MCERemoteButtons.Unknown Then RaiseEvent ButtonPressed(_button) Return True If _blnDebugMode Then Debug.WriteLine("code " + bRawData(0).ToString + ":" + bRawData(1).ToString + " = " + _button.ToString) End If End If Finally If Not buffer.Equals(IntPtr.Zero) Then Marshal.FreeHGlobal(buffer) End Try End Select Return False End Function End Class [/code] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Code for MCE remote
Contact us
RSS
Top
Bottom