Skip to content

Instantly share code, notes, and snippets.

@chrismatthieu
Created September 27, 2012 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismatthieu/3796468 to your computer and use it in GitHub Desktop.
Save chrismatthieu/3796468 to your computer and use it in GitHub Desktop.
bash script with TTS for announcing wire colors touched via Makey Makey device
#!/bin/bash
while :
do
_key()
{
local kp
ESC=$'\e'
_KEY=
read -d '' -sn1 _KEY
case $_KEY in
"$ESC")
while read -d '' -sn1 -t1 kp
do
_KEY=$_KEY$kp
case $kp in
[a-zA-NP-Z~]) break;;
esac
done
;;
esac
printf -v "${1:-_KEY}" "%s" "$_KEY"
}
_key x
case $x in
$'\e[11~' | $'\e[OP') key=F1 ;;
$'\e[12~' | $'\e[OQ') key=F2 ;;
$'\e[13~' | $'\e[OR') key=F3 ;;
$'\e[14~' | $'\e[OS') key=F4 ;;
$'\e[15~') key=F5 ;;
$'\e[16~') key=F6 ;;
$'\e[17~') key=F7 ;;
$'\e[18~') key=F8 ;;
$'\e[19~') key=F9 ;;
$'\e[20~') key=F10 ;;
$'\e[21~') key=F11 ;;
$'\e[22~') key=F12 ;;
$'\e[A' ) key=UP
say "you touched the red wire" ;;
$'\e[B' ) key=DOWN
say "you touched the blue wire" ;;
$'\e[C' ) key=RIGHT
say "you touched the yellow wire" ;;
$'\e[D' ) key=LEFT
say "you touched the green wire" ;;
?) key=$x ;;
*) key=??? ;;
esac
echo "You have pressed $key"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment