Results 1 to 5 of 5

Thread: Remote control example code?

  1. #1
    Join Date
    Sep 2013
    Location
    USA
    Posts
    87

    Remote control example code?

    Are there any examples of how to capture remote control commands so I can build my own custom NextPVR client?
    I am working with this bit of code but I get nothing when
    Code:
    public void RegisterRemote()
            {            
                RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[4];
    
                rid[0].usUsagePage = 0xFFBC;      // adds HID remote control
                rid[0].usUsage = 0x88;
                rid[0].dwFlags = 0;
                rid[0].hwndTarget = fForm.Handle;
    
                rid[1].usUsagePage = 0x0C;      // adds HID remote control
                rid[1].usUsage = 0x01;
                rid[1].dwFlags = RIDEV_INPUTSINK;
                rid[1].hwndTarget = fForm.Handle;
    
                rid[2].usUsagePage = 0x0C;      // adds HID remote control
                rid[2].usUsage = 0x80;
                rid[2].dwFlags = RIDEV_INPUTSINK;
                rid[2].hwndTarget = fForm.Handle;
    
                //rid[0].usUsagePage = 0x01;      // adds HID mouse with no legacy messages
                //rid[0].usUsage = 0x02;
                //rid[0].dwFlags = RIDEV_NOLEGACY;
    
                rid[3].usUsagePage = 0x01;      // adds HID keyboard with no legacy message
                rid[3].usUsage = 0x06;
                rid[3].dwFlags = RIDEV_NOLEGACY;
                uint theSize = (uint)Marshal.SizeOf(rid[0]);
                if (!RegisterRawInputDevices(rid, (uint)rid.Length, theSize))
                    throw new ApplicationException("Failed to register raw input devices.");        
            }

    It runs without error but I get nothing in the WndProc override when I press remote buttons.

    Really frustrating.

    Jim Margarit

  2. #2
    Join Date
    Nov 2003
    Location
    NextPVR HQ, Wellington, New Zealand
    Posts
    87,342
    I think this was the original article I read on it:
    https://msdn.microsoft.com/en-us/library/ms996387.aspx

    Remember, it'll only work with MCE remote and receiver though, not just any remote.

  3. #3
    Join Date
    Sep 2013
    Location
    USA
    Posts
    87
    Quote Originally Posted by sub View Post
    I think this was the original article I read on it:
    https://msdn.microsoft.com/en-us/library/ms996387.aspx

    Remember, it'll only work with MCE remote and receiver though, not just any remote.
    Yes, that article is my primary source of info. It is outdated as it doesn't compile and actually has this line of code in it:
    Code:
    Marshal.FreeHGlobal(pRawInputDeviceList);Device, uint uiCommand, IntPtr 
    pData, ref uint pcbSize);
    I'm thinking it is a cut and paste error or it that actually syntax that I'm not familiar with?

    I'm using the same "Microsoft eHome Infrared transceiver" that I use with my NextPVR setup. GetRawDeviceInfo enumerates it as a IrDevice. That much of the code is working well.
    Interestingly, the code I posted has one entry commented out.
    Code:
    //rid[0].usUsagePage = 0x01;      // adds HID mouse with no legacy messages
                //rid[0].usUsage = 0x02;
                //rid[0].dwFlags = RIDEV_NOLEGACY;
    If I register this device, my main window stops responding to the mouse and keyboard. Those events are going somewhere but I don't know where.
    I'm thinking that the hwndTarget is incorrect but I only have one window and that's the handle I pass.

    My main interest was if any of the other clients have source code that uses the remote control code.

    Thanks,

    Jim

  4. #4
    Join Date
    Nov 2003
    Location
    NextPVR HQ, Wellington, New Zealand
    Posts
    87,342
    I haven't looked at this code in maybe 10 years, but this is what I'm using this:

    Code:
                    RAWINPUTDEVICE[] Rid = new RAWINPUTDEVICE[2];
                    const int RIDEV_INPUTSINK = 0x00000100;
                    const int RIDEV_NOLEGACY = 0x00000030;
                    const int RIDEV_APPKEYS = 0x00000400;
                    const int RIDEV_NOHOTKEYS = 0x00000200;
    
    
                    Rid[0].usUsagePage = 0xFFBC; //adds most MCE remote buttons
                    Rid[0].usUsage = 0x88;
                    Rid[0].dwFlags = RIDEV_INPUTSINK | (0x03 & (RIDEV_NOLEGACY | RIDEV_APPKEYS | RIDEV_NOHOTKEYS));
                    Rid[0].hwndTarget = parent.Handle;
    
                    Rid[1].usUsagePage = 0x0C;   // adds MCE remote control - more info, details, guide buttons
                    Rid[1].usUsage = 0x01;
                    Rid[1].dwFlags = RIDEV_INPUTSINK | ((0x03 >> 8) & (RIDEV_NOLEGACY | RIDEV_APPKEYS | RIDEV_NOHOTKEYS));
                    Rid[1].hwndTarget = parent.Handle;
    
                    if (RegisterRawInputDevices(Rid, (uint)2, (uint)Marshal.SizeOf(Rid[0])) == false)
                    {
                        Logger.Error("Error registering raw input devices");
                    }
    (Though I can see a weird shift in there that doesn't make a lot of sense)

  5. #5
    Join Date
    Sep 2013
    Location
    USA
    Posts
    87
    Thanks for the code snippet. I write code in a virtual machine for portability between computers and to limit the carnage of rogue code. It bit me in the butt here. The VMware vm messes with RawInputDevices somehow and the code just doesn't work. I had to install Visual Studio on the host machine for this one project and it works fine now. I grieve for the wasted hours trying to fix this.

    Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •