#!/bin/sh # Minimalist touchscreen keyboard, based on any input and timeouts. # Cycles through letters as long as there is constant input, # (produced by twiddling thumbs or circling on a touchscreen) # short pause goes to the next letter (represented _) # long pause ends input (represented by .) touchdevice=/dev/input/mice alphabet="0 1 2 3 4 5 6 7 8 9" inputwait=0.20 wordwait=2.00 eofwait=5.00 touchevent() { sleep 0.1 cat "$1" | dd bs=1 count=1 >& /dev/null } twiddlethumbs() { echo "Twiddlethumbs:" 1>&2 sleep 999999 & wordwaitpid=$! sleep 999999 & eofwaitpid=$! while touchevent "$touchdevice" do # Add to phrase if input wait has passed if [ ! -e /proc/$wordwaitpid ] then phrase="$phrase""$wordselect" fi # Stop if EOF wait has passed if [ ! -e /proc/$eofwaitpid ] then break fi # Reset timeouts. kill $wordwaitpid $eofwaitpid >& /dev/null wait $wordwaitpid $eofwaitpid >& /dev/null sleep $wordwait && echo -n '_' 2>&1 & wordwaitpid=$! sleep $eofwait && echo -n '.' 2>&1 & eofwaitpid=$! # Show next word: wordselect="$1" shift set -- "$@" "$wordselect" echo -n -e '\r\033[2K'"$phrase""$wordselect" 1>&2 done echo 1>&2 echo -n "$phrase" } twiddlethumbs $alphabet