ubuntuusers.de

Titel:
Twiddle Thumbs Touchscreen Keyboard
Autor:
frostschutz
Datum:
10. Januar 2018 04:08
Aktionen:
Code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/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