| 1 | #!/bin/bash |
| 2 | # Test what escape sequences the terminal sends for function keys |
| 3 | |
| 4 | echo "Press keys to see their escape sequences (Ctrl+C to quit):" |
| 5 | echo "Try: F12, Shift-F12, F8, F4, F6, F2" |
| 6 | echo "" |
| 7 | |
| 8 | # Read raw input and show escape sequences |
| 9 | while true; do |
| 10 | read -rsn1 char |
| 11 | if [[ $char == $'\e' ]]; then |
| 12 | # Start of escape sequence |
| 13 | seq="$char" |
| 14 | # Read the rest quickly |
| 15 | while read -rsn1 -t 0.001 char; do |
| 16 | seq="$seq$char" |
| 17 | done |
| 18 | # Show it in a readable format |
| 19 | echo -n "Escape sequence: " |
| 20 | echo -n "$seq" | od -An -tx1 | tr -d ' \n' |
| 21 | echo " (raw: $(echo -n "$seq" | cat -v))" |
| 22 | else |
| 23 | echo "Character: '$char' (ASCII: $(printf '%d' "'$char"))" |
| 24 | fi |
| 25 | done |