Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env bash
#
# react to cec keypresses in the jankiest way possible
#
# Author: Dave Eddy <dave@daveeddy.com>
# Date: 10/15/2013
# Licens: MIT
# Tested on: Raspberry pi with libcec compiled from soure
KEYS_ESC=$'\e'
KEYS_F1=$'\e'[[A
KEYS_F2=$'\e'[[B
KEYS_F3=$'\e'[[C
KEYS_F4=$'\e'[[D
KEYS_F5=$'\e'[[E
KEYS_F6=$'\e'[17~
KEYS_F7=$'\e'[18~
KEYS_F8=$'\e'[19~
KEYS_F9=$'\e'[20~
KEYS_F10=$'\e'[21~
KEYS_F11=$'\e'[22~
KEYS_F12=$'\e'[23~
KEYS_HOME=$'\e'[1~
KEYS_HOME2=$'\e'[H
KEYS_INSERT=$'\e'[2~
KEYS_DELETE=$'\e'[3~
KEYS_END=$'\e'[4~
KEYS_END2=$'\e'[F
KEYS_PAGEUP=$'\e'[5~
KEYS_PAGEDOWN=$'\e'[6~
KEYS_UP=$'\e'[A
KEYS_DOWN=$'\e'[B
KEYS_RIGHT=$'\e'[C
KEYS_LEFT=$'\e'[D
KEYS_NUMPADUNKNOWN=$'\e'[G
onright() {
echo 'right button pressed'
echo -ne $KEYS_RIGHT > /tmp/cmd
}
onleft() {
echo 'left button pressed'
echo -ne $KEYS_LEFT > /tmp/cmd
}
ondown() {
echo 'down button pressed'
echo -ne $KEYS_DOWN > /tmp/cmd
}
onup() {
echo 'up button pressed'
echo -ne $KEYS_UP > /tmp/cmd
}
onselect() {
echo 'select button pressed'
echo -ne p > /tmp/cmd
}
onplay() {
echo 'play button pressed'
}
onpause() {
echo 'pause button pressed'
}
onforward() {
echo 'forward button pressed'
}
onbackward() {
echo 'back button pressed'
}
onexit(){
echo 'exit button pressed'
echo -ne '>' > /tmp/cmd
}
onclear(){
echo 'clear button pressed'
echo -ne z > /tmp/cmd
}
onF1() { echo -ne 1 > /tmp/cmd ;}
onF2() { echo -ne 2 > /tmp/cmd ;}
onF3() { echo -ne '<' > /tmp/cmd ;}
onF4() { echo -ne '>' > /tmp/cmd ;}
filter() {
\grep --line-buffered -Po '(?<=key released: )\w+\s(((\w+)?\s?(\w+)?)?\s?\(\w+\))'
}
echo as | cec-client | filter | \
while read cmd; do
case "$cmd" in
right*) onright;;
left*) onleft;;
down*) ondown;;
up*) onup;;
select*) onselect;;
play*) onplay;;
pause*) onpause;;
forward*) onforward;;
backward*) onbackward;;
exit*) onexit;;
clear*) onclear;;
F1*) onF1;;
F2*) onF2;;
F3*) onF3;;
F4*) onF4;;
*)
echo "'$cmd'"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment