3

My TV supports CEC and is connected to my Raspberry Pi with HDMI. I've installed cec-client on the Pi and followed this tutorial, but it only explains how to turn the TV on and off with the Pi. What I want is to somehow grab a signal in the Pi when a button on the TV remote is pressed, to know what button is pressed. I tried running cec-client until it outputs "waiting for input", but pressing buttons on the TV remote didn't do anything.

2

I've had the same issue, that the remote controll buttons haven't been recognized after typing the command cec-client. In order to work I had to refocus the TV's input source after the waiting for input occured, so for example I changed from HDMI 1 (thats where the Pi was connected to) to HDMI 2 and back to HDMI 1 again via the remote manually.

After that I was able to catch the remote control signals.

If you want to controll your Pi you also need to download xdotool in order to simulate keyboard input. Type:

sudo apt-get install xdotool

Second step is to create an executable script with

touch name.sh
chmod +x name.sh

#open the script with your favorite editor
nano name.sh

You can now start to program your controlls.

#!/bin/bash
while read oneline
do
   keyline=$(echo $oneline | grep " key ")
   if [ -n "$keyline" ]; then
      strkey=$(grep -oP '(?<=sed: ).*?(?= \()' <<< "$keyline")
      strstat=$(grep -oP '(?<=key ).*?(?=:)' <<< "$keyline")
      strpressed=$(echo $strstat | grep "pressed")

      if [ -n "$strpressed" ]; then
         case "$strkey" in
            "1")
                xdotool key "1"
                ;;
            "2")
                xdotool key "2"
                ;;
            "3")
                xdotool key "3"
                ;;
            "4")
                xdotool key "4"
                ;;
            "5")
                xdotool key "5"
                ;;
            "6")
                xdotool key "6"
                ;;
            "7")
                xdotool key "7"
                ;;
            "8")
                xdotool key "8"
                ;;
            "9")
                xdotool key "9"
                ;;
            "0")
                xdotool key "0"
                ;;
         esac
      fi
   fi
done

This is a simple programm that sends the digits as keys when pressed the according button on the remote.

Now you can execute your script

cec-client | ./name.sh

It should be working now

If you want to learn more about that check out this link: https://ubuntu-mate.community/t/controlling-raspberry-pi-with-tv-remote-using-hdmi-cec/4250

It tells you also how to auto execute the script when booting

Futhermore you can find xdotool commands here: https://www.linux.org/threads/xdotool-keyboard.10528/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.