diff options
author | nea <romangraef@gmail.com> | 2022-01-13 00:01:56 +0100 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-01-13 00:01:56 +0100 |
commit | d9031203e22e4ef381c482b4594521323647487e (patch) | |
tree | 1ea7dcfb53840a42f10d19cf25317138e497911a /readkey | |
download | scripts-d9031203e22e4ef381c482b4594521323647487e.tar.gz scripts-d9031203e22e4ef381c482b4594521323647487e.tar.bz2 scripts-d9031203e22e4ef381c482b4594521323647487e.zip |
Initial commit
Diffstat (limited to 'readkey')
-rwxr-xr-x | readkey | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -0,0 +1,36 @@ +#!/bin/bash + +if [ "a$1" == "a-h" ] || [ "a$1" == "a--help" ]; then + cat <<EOF +Usage: $0 + +Reads a single key from stdin and parses some key codes such as arrow keys and enter. +EOF +fi +read -rsN1 key + +read -rsN1 -t 0.0001 k1 +read -rsN1 -t 0.0001 k2 +read -rsN1 -t 0.0001 k3 +key+="${k1}${k2}${k3}" + +case "$key" in +$'\e[A' | $'\e0A') + echo up + ;; +$'\e[D' | $'\e0D') + echo left + ;; +$'\e[B' | $'\e0B') + echo down + ;; +$'\e[C' | $'\e0C') + echo right + ;; +$'\n') + echo enter + ;; +*) + echo "$key" + ;; +esac |