Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Can't trap directional pad

If you have a question or need help, this is the place to be.
Post Reply
doveman
Posts: 17
Joined: Tue Apr 24, 2012 10:51 pm

Can't trap directional pad

Post by doveman »

I had this MCE-type remote working with EventGhost and Mediaportal on another PC but I've moved it now and can't remember what I had to do to get it working.

Most of the keys do work and are mapped in EG to Mediaportal/Message Plugin, it's just the directional keys I can't sort out as they are detected as Keyboard Down/Up/Left/Right and OK is Keyboard Return. So if I enable the Plugin:Keyboard in EG, it does trap them but also disables those keys from working on my actual keyboard, which is not how it was on the other PC. If I disable the Plugin:Keyboard then they're just not detected at all in EG.

There's four devices that show for the remote, so I've added four Plugin:HID:BTC USB Multimedia Cordless Keyboard.

I've disabled the HID service and the MCE Receiver and Scheduler services. I've also zeroed out the RC6 remote registry entry as below:

Code: Select all

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HidIr\Remotes\745a17a0-74d3-11d0-b6fe-00a0c90f57da]
"CodeSetNum0"=dword:00000000 ;
"CodeSetNum1"=dword:00000000 ;These four values put the standard global windows keys out of function. These are
"CodeSetNum2"=dword:00000000 ;volume +, -, mute and .... windows sleep mode. I so hated that button
"CodeSetNum3"=dword:00000000 ;
"ReportMappingTable"=hex:\
	00,00,00,00,00,00,00,\
	01,00,00,00,00,00,00,\
	02,00,00,00,00,00,00,\
	03,00,00,00,00,00,00,\
	04,00,00,00,00,00,00,\
	05,00,00,00,00,00,00,\
	06,00,00,00,00,00,00,\
	07,00,00,00,00,00,00,\
	08,00,00,00,00,00,00,\
	09,00,00,00,00,00,00,\
	0a,00,00,00,00,00,00,\
	0b,00,00,00,00,00,00,\
	0c,00,00,00,00,00,00,\
	0e,00,00,00,00,00,00,\
	0f,00,00,00,00,00,00,\
	10,00,00,00,00,00,00,\
	11,00,00,00,00,00,00,\
	12,00,00,00,00,00,00,\
	13,00,00,00,00,00,00,\
	14,00,00,00,00,00,00,\
	15,00,00,00,00,00,00,\
	16,00,00,00,00,00,00,\
	17,00,00,00,00,00,00,\
	18,00,00,00,00,00,00,\
	19,00,00,00,00,00,00,\
	1a,00,00,00,00,00,00,\
	1b,00,00,00,00,00,00,\
	1c,00,00,00,00,00,00,\
	1d,00,00,00,00,00,00,\
	1e,00,00,00,00,00,00,\
	1f,00,00,00,00,00,00,\
	20,00,00,00,00,00,00,\
	21,00,00,00,00,00,00,\
	22,00,00,00,00,00,00,\
	23,00,00,00,00,00,00,\
	26,00,00,00,00,00,00,\
	29,00,00,00,00,00,00,\
	2a,00,00,00,00,00,00,\
	3b,00,00,00,00,00,00,\
	4e,00,00,00,00,00,00,\
	6e,00,00,00,00,00,00
So I'm at a loss now and am very frustrated, so would appreciate any help if someone knows what I need to do.
doveman
Posts: 17
Joined: Tue Apr 24, 2012 10:51 pm

Re: Can't trap directional pad

Post by doveman »

Can anyone help me with this?

It's extremely annoying as every time I leave my desk and try to use the remote and watch TV, I realise I haven't enabled the Keyboard plugin and so I can't use the D-Pad and I have to disable it every time I use the PC for anything else, otherwise the Enter key doesn't work.
blaher
Experienced User
Posts: 487
Joined: Thu Nov 17, 2011 1:27 am

Re: Can't trap directional pad

Post by blaher »

doveman wrote:I had this MCE-type remote
Can you use the MCE Remote plugin?
So if I enable the Plugin:Keyboard in EG, it does trap them but also disables those keys from working on my actual keyboard
That's unusual. I use the keyboard plug-in, but it doesn't disable my keys, just logs them as events when pressed.
There's four devices that show for the remote, so I've added four Plugin:HID:BTC USB Multimedia Cordless Keyboard.
I have 4 devices associated with my remote, but I just use 1 plug-in: MCE Remote for Vista/Win7
I've disabled the HID service
I haven't done that. Perhaps something to try...
I realise I haven't enabled the Keyboard plugin and so I can't use the D-Pad and I have to disable it every time I use the PC for anything else, otherwise the Enter key doesn't work.
You can enable/disable an item like a plug-in, just like folders, automatically. So if you get a trigger Task.Activated.ehshell, for example if you use WMC, you could enable keyboard, and then disable it on exit/deactivation.
doveman
Posts: 17
Joined: Tue Apr 24, 2012 10:51 pm

Re: Can't trap directional pad

Post by doveman »

blaher wrote:Can you use the MCE Remote plugin?
Hi, thanks for the reply.

Unfortunately not as it's not a 'real' MCE remote (which I think sends unique codes for the D-pad and number pad, rather than presenting as a keyboard device and sending Enter when OK is pressed).
That's unusual. I use the keyboard plug-in, but it doesn't disable my keys, just logs them as events when pressed.
Yes but as well as enabling the keyboard plug-in, I have to then map the keys to Mediaportal Items (Cursor Up, Cursor Down, etc) on the right and it's this which prevents the keyboard keys working, as they get trapped and redirected to Mediaportal as well.
I have 4 devices associated with my remote, but I just use 1 plug-in: MCE Remote for Vista/Win7
I think only two of the devices are actually needed, as monitoring with the OtherHidInfo script in AHK shows that all the keys are on one or the other of these (except the D-Pad, Number pad and Power button which aren't on anything)
HID\VID_046E&PID_5577&MI_01&Col03#8&1237ef0& Page 65468, Usage 136 (this is the shortcuts (except Guide) and teletext buttons, plus the MCE button)
HID\VID_046E&PID_5577&MI_01&Col02#8&1237ef0& Page 12, Usage 1 (this is all the other buttons, plus the Guide shortcut button)
I haven't done that. Perhaps something to try...
I'm pretty sure it needs to be disabled for this remote. I can't remember exactly why, might be because it's not a real MCE remote or something to do with Mediaportal compatibility.
You can enable/disable an item like a plug-in, just like folders, automatically. So if you get a trigger Task.Activated.ehshell, for example if you use WMC, you could enable keyboard, and then disable it on exit/deactivation.
I don't think that will work as Mediaportal won't be activated until I press a button that's also set in EG to bring Mediaportal into focus and once that's happened I can just use the D-pad even without the keyboard plugin. The problem is if Mediaportal is already on the EPG or videos/music list and the user want's to navigate it but the D-pad won't work until they press another key to bring MP into focus and that will do something unwanted, like take them out of the EPG so they'll have to navigate back to it.

I'm trying to adapt the Conceptronic WinUSB plugin now. I've got it installed so now there's only two entries in Device Manager for the remote, "Emprex MCE USB (Buttons)" and "Emprex MCE USB (Keypad)", as per my script. I've got somewhere as with the script (below, I've attached it as well in case it's easier to download it to look at it). EG now registers Emprex.Up, Emprex.Down, Emprex.OK and also the Num keys, (i.e everything in the Keypad_Codes section) and they don't send keys to any other program, which is great but it doesn't register any of the other keys (all those in the Button_Codes section) so obviously I haven't got it right yet, so if you can see where I've gone wrong I'd appreciate your help as I'm just trying things and seeing if they work, without really knowing what I should be doing but I feel pretty close!. I see the __init__.pyc gets auto-generated/edited, so that now points to the Emprex plugin I've made, rather than the Conceptronic one I copied it from, so that should be OK I guess.

I imagine the problem's in the last section "def ButtonsCallback(self, data):", something to do with the self.expectedLength check but I don't really understand how that works.

Code: Select all

# -*- coding: utf-8 -*-
#
# This file is a plugin for EventGhost.
# Copyright (C) 2005-2009 Lars-Peter Voss <[email protected]>
#
# EventGhost is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the
# Free Software Foundation;
#
# EventGhost is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

ur"""<rst>
Plugin for the `Emprex USB MCE Remote Control `__.

|

.. image:: picture.jpg
   :align: center

__ http://www.emprex.com/02_products_02.php?id=303
"""

import eg

eg.RegisterPlugin(
    name = "Emprex MCE USB",
    author = "doveman",
    version = "1.0.0",
    kind = "remote",
    guid = "{745a17a0-74d3-11d0-b6fe-00a0c90f57da}",
    description = __doc__,
    hardwareId = "USB\\VID_046E&PID_5577",
)


BUTTON_CODES = {
	(2, 178): 'Record',
	(2, 177): 'Pause',
	(2, 183): 'Stop',
	(2, 180): 'Rewind',
	(2, 176): 'Play',
	(2, 179): 'FFwd',
	(2, 182): 'Skip <',
	(2, 181): 'Skip >',
	(2, 36): 'Back',
	(2, 9): 'Info',
	(2, 233): 'Vol+',
	(2, 234): 'Vol-',
	(2, 226): 'Mute',
	(2, 156): 'Ch +',
	(2, 157): 'Ch -',
	(2, 141): 'Guide',
	(3, 13): 'MCE',
	(3, 72): 'Rec TV',
	(3, 37): 'Live TV',
	(3, 36): 'DVD Menu',
	(3, 71): 'Music',
	(3, 73): 'Pics',
	(3, 74): 'Video',
	(3, 80): 'Radio',
	(3, 90): 'Teletext',
	(3, 91): 'Red',
	(3, 92): 'Green',
	(3, 93): 'Blue',
	(3, 94): 'Yellow',
    (2,): 'Power',
}

KEYPAD_CODES = {
    (0, 0, 30, 0, 0, 0, 0, 0): "Num1",
    (0, 0, 31, 0, 0, 0, 0, 0): "Num2",
    (0, 0, 32, 0, 0, 0, 0, 0): "Num3",
    (0, 0, 33, 0, 0, 0, 0, 0): "Num4",
    (0, 0, 34, 0, 0, 0, 0, 0): "Num5",
    (0, 0, 35, 0, 0, 0, 0, 0): "Num6",
    (0, 0, 36, 0, 0, 0, 0, 0): "Num7",
    (0, 0, 37, 0, 0, 0, 0, 0): "Num8",
    (0, 0, 38, 0, 0, 0, 0, 0): "Num9",
    (0, 0, 39, 0, 0, 0, 0, 0): "Num0",
    (0, 0, 40, 0, 0, 0, 0, 0): "Ok",
    (0, 0, 41, 0, 0, 0, 0, 0): "Clear",
    (0, 0, 79, 0, 0, 0, 0, 0): "Right",
    (0, 0, 80, 0, 0, 0, 0, 0): "Left",
    (0, 0, 81, 0, 0, 0, 0, 0): "Down",
    (0, 0, 82, 0, 0, 0, 0, 0): "Up",
    (2, 0, 37, 0, 0, 0, 0, 0): "Star",
    (2, 0, 32, 0, 0, 0, 0, 0): "Dash",
}


class Emprex(eg.PluginBase):

    def __start__(self):
        self.buffer = []
        self.expectedLength = 0
        self.winUsb = eg.WinUsb(self)
        self.winUsb.Device(self.KeypadCallback, 8, True).AddHardwareId(
            "Emprex MCE USB (Keypad)", "USB\\VID_046E&PID_5577&MI_00"
        )
        self.winUsb.Device(self.ButtonsCallback, 1).AddHardwareId(
            "Emprex MCE USB (Buttons)", "USB\VID_046E&PID_5577&MI_01"
        )
        self.winUsb.Start()


    def __stop__(self):
        self.winUsb.Stop()


    def KeypadCallback(self, data):
        if data == (0, 0, 0, 0, 0, 0, 0, 0):
            self.EndLastEvent()
        else:
            self.TriggerEnduringEvent(KEYPAD_CODES[data])


    def ButtonsCallback(self, data):
        value = data[0]
        numReceived = len(self.buffer)
        if self.expectedLength == 0:
            if value not in (2, 3, 4):
                return
            self.expectedLength = {2: 1, 3: 4, 4: 2}[value]
        elif numReceived < self.expectedLength - 1:
            self.buffer.append(value)
        elif numReceived == self.expectedLength - 1:
            self.buffer.append(value)
            value = tuple(self.buffer)
            if value in BUTTON_CODES:
                self.TriggerEnduringEvent(BUTTON_CODES[value])
            else:
                self.EndLastEvent()
            self.buffer = []
            self.expectedLength = 0
        else:
            self.PrintError("Unknown data received")
            self.buffer = []
            self.expectedLength = 0
            self.EndLastEvent()

Attachments
__init__.py
(4.1 KiB) Downloaded 163 times
doveman
Posts: 17
Joined: Tue Apr 24, 2012 10:51 pm

Re: Can't trap directional pad

Post by doveman »

Wow, I seem to have managed to work it out myself by trial and error :)

Every button now registers in EG with the attached script.
Attachments
__init__.py
(4.02 KiB) Downloaded 192 times
doveman
Posts: 17
Joined: Tue Apr 24, 2012 10:51 pm

Re: Can't trap directional pad

Post by doveman »

This is just weird. After working fine since my last post, today I went to use my remote and it wasn't working and the light was stuck on the receiver. So I unplugged it and reconnected it and it started working after that but EG was just throwing up errors, so I rebooted but that didn't help.

What's happened is that it's decided all the codes have changed so that I have to change the last digit from 0 to 164, so where before I had

(2, 141, 0, 0, 0, 0, 0, 0): 'Guide',

in my EG Plugin __init__.py I now need

(2, 141, 0, 0, 0, 0, 0, 164): 'Guide',

and I've had to change this for every entry.

Why would it suddenly change the keycode it sends/receives like this?
doveman
Posts: 17
Joined: Tue Apr 24, 2012 10:51 pm

Re: Can't trap directional pad

Post by doveman »

Well it seems the last digit changes every time I re-sync the remote and receiver (perhaps when moving the receiver to a different USB port as well). Is there anyway to use a wildcard for the last digit (i.e. 164) in the script so that I don't have to edit it everytime I resync or move the receiver?
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Can't trap directional pad

Post by Pako »

You can try the attached file.
I think so it might work.
However, I'm not sure, I do not have the opportunity to try it.

Pako
Attachments
__init__.py
(3.96 KiB) Downloaded 193 times
doveman
Posts: 17
Joined: Tue Apr 24, 2012 10:51 pm

Re: Can't trap directional pad

Post by doveman »

Thanks, I'll give it a try.

EDIT: Cool, that works fine thanks. No more having to edit the script :D
Post Reply