When I run this script
#!/usr/bin/python3
import cec
import uinput
import time
u = uinput
KEYMAP = {
0: u.KEY_ENTER,
1: u.KEY_UP,
2: u.KEY_DOWN,
3: u.KEY_LEFT,
4: u.KEY_RIGHT,
9: u.KEY_HOMEPAGE,
10: u.KEY_MENU,
13: u.KEY_BACK,
44: u.KEY_HOMEPAGE,
68: u.KEY_PLAY,
69: u.KEY_STOP,
70: u.KEY_PAUSE,
75: u.KEY_FASTFORWARD,
76: u.KEY_REWIND,
103: u.KEY_HOMEPAGE,
113: u.KEY_BLUE,
114: u.KEY_RED,
115: u.KEY_YELLOW,
116: u.KEY_GREEN
}
cec.init()
device = uinput.Device(KEYMAP.values())
print("Ready")
keystate = None
def onkey(event, key, state):
assert event == 2
global keystate
if state == 0 and keystate is None:
print("Got Key", key, "state", state)
keystate = "down"
device.emit(KEYMAP[key], 1)
if state > 0:
if keystate is None:
print("Got key", key, "state", state)
device.emit(KEYMAP[key], 1)
print("Key {0} up after {1}".format(key, state))
device.emit(KEYMAP[key], 0)
keystate = None
cec.add_callback(onkey, cec.EVENT_KEYPRESS)
while True:
time.sleep(9e9)
I get
Traceback (most recent call last):
File "/home/mycroft/.config/autostart-scripts/cec-daemon.py", line 31, in <module>
cec.init()
AttributeError: module 'cec' has no attribute 'init'
I have Ubuntu 21.10 rpi4 the libcec6 libcec-dev and python3-cec packages installed.