Skip to content

cec.EVENT_KEYPRESS not working after updating to 0.2.7 #33

Open

Description

@superuser789

Hi,
In previous cec 0.2.6, the following code was working fine. But it is not working now after updating to 0.2.7.

import cec
import time


cec.init()

print("Ready")

def onkey(event, key , state):
  if state > 0:
    print("Got key", key, "state", state)

cec.add_callback(onkey, cec.EVENT_KEYPRESS)

while True:
 time.sleep(9e8)

What changes should I do to make it work again ?

Thanks.

Activity

  1. nforro commented on May 5, 2019

    @nforro
    Collaborator

    Sorry for late reply. Could you be more specific? I just tried your code and it works fine.

  2. TheNetStriker commented on Sep 19, 2019

    @TheNetStriker

    I just tried this on my Raspberry Pi 4 I'm also getting no events with 2.7. I also tried with EVENT_ALL, but I don't receive anyting, but power_on and standby are working. Any idea what could be the problem?

    Edit: I found keys that are working, but I'm looking for an event when the device enters standby or is powered on externally. Is this already possible?

  3. nforro commented on Sep 20, 2019

    @nforro
    Collaborator

    @TheNetStriker Yes, for example my TV broadcasts CEC_OPCODE_ROUTING_CHANGE (with new address parameter set to 1.0.0.0) after it's powered on, and it broadcasts CEC_OPCODE_STANDBY when it enters standby. So just use EVENT_COMMAND callback and monitor commands your device broadcasts.

  4. TheNetStriker commented on Sep 20, 2019

    @TheNetStriker

    I just tested this with the following code:

    def onCommand(event, cmd, convert_cmd):
        print("cmd", cmd, "convert_cmd", convert_cmd)
    
    cec.add_callback(onCommand, cec.EVENT_COMMAND)
    

    But I don't get any events. Is there any way to debug this?

  5. nforro commented on Sep 20, 2019

    @nforro
    Collaborator

    There are only two arguments to the callback, you should use def onCommand(event, cmd):.
    Set up a log callback, or run cec-client from libcec and examine the logs, all communication should be there.

  6. TheNetStriker commented on Sep 20, 2019

    @TheNetStriker

    Thanks for the quick help. I managed to the the power events with this code:

    def onCommand(event, cmd):
        #print("event", event, "cmd", cmd)
        opcode = cmd["opcode"]
        parameters = cmd["parameters"]
        if opcode == cec.CEC_OPCODE_STANDBY:
            PublishTvIsOn(False)
        if opcode == cec.CEC_OPCODE_ROUTING_CHANGE and parameters == b'\x00\x00@\x00':
            PublishTvIsOn(True)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions