This tool maps CEC (Consumer Electronics Control) key events to uinput keyboard and mouse events, allowing you to control your Linux system with a TV remote that supports the CEC protocol. This is mainly used for controlling a Raspberry Pi or similar devices connected to a TV via HDMI, but it should work with any Linux system that supports CEC and uinput.
cec-keyboard [flags]
You need to have access to /dev/uinput. This can be achieved by:
-
Adding your user to the
inputgroup:sudo usermod -aG input $USERAfter running this command, you may need to log out and back in for the group change to take effect.
-
Ensuring the
/dev/uinputdevice exists and is writable by your user. using udev rules:sudo tee /etc/udev/rules.d/99-uinput.rules <<EOF KERNEL=="uinput", GROUP="input", MODE="0660" EOF
After creating the udev rule, reload the udev rules and trigger them:
sudo udevadm control --reload-rules sudo udevadm trigger
-config(optional): Path to the configuration file. Default isconfig.yaml.-log-level(optional): Set the logging level. Options: debug, info, warn, error. Default: info.
# Run with default config.yaml file
cec-keyboard
# Use a specific config file with debug logging
cec-keyboard -config my-config.yaml -log-level debug
The configuration file uses YAML format with the following structure:
adapter: /dev/cec0 # Optional: CEC adapter name/path
name: cec-keyboard # Optional: CEC device name
type: recording # Optional: CEC device type (tv, recording, tuner, playback, audio)
mappings:
- cecCode: 0 # CEC key code from remote
actions: # List of actions to perform, can be multiple
- keyboard: # Keyboard action
type: press # Action type (press, down, up)
code: 1 # uinput key code (1 is Escape)
- cecCode: 103
actions:
- keyboard:
type: press
code: 103 # Up arrow key
- cecCode: 108 # Can have multiple actions for one CEC code
actions:
- keyboard:
type: press
code: 108 # Down arrow key
- keyboard:
type: press
code: 28 # Enter key
# Mouse actions example
- cecCode: 10
actions:
- mouse:
leftClick: {} # Perform left mouse click
- cecCode: 11
actions:
- mouse:
rightClick: {} # Perform right mouse click
- cecCode: 12
actions:
- mouse:
moveX: 10 # Move mouse 10 pixels right
- cecCode: 13
actions:
- mouse:
moveY: -10 # Move mouse 10 pixels uppress: Simulates pressing and releasing a keydown: Simulates pressing a key down (without releasing)up: Simulates releasing a key
leftClick: Simulates a left mouse button clickrightClick: Simulates a right mouse button clickmiddleClick: Simulates a middle mouse button clicksideClick: Simulates a side mouse button clickmoveX: Moves the mouse cursor horizontally (positive value for right, negative for left)moveY: Moves the mouse cursor vertically (positive value for down, negative for up)
You can define multiple actions for the same CEC key code, allowing for complex control schemes.
You can run the application with an empty or minimal mapping configuration and check the logs to see the CEC key codes that are received from your remote. Set the log level to debug to see additional information:
cec-keyboard -log-level debug
The CEC key codes are typically integers that correspond to specific buttons on your remote control.
You can find the list of uinput key codes in the Linux kernel documentation or by checking the uinput_defs.go file in the go-uinput library.