Skip to content

Instantly share code, notes, and snippets.

@jdloft
Created October 26, 2016 19:08
Show Gist options
  • Save jdloft/11af875345e3b033eb0a6cd157e37c21 to your computer and use it in GitHub Desktop.
Save jdloft/11af875345e3b033eb0a6cd157e37c21 to your computer and use it in GitHub Desktop.
Keyboard testing script
#!/bin/bash
function findInArray() {
local n=$#
local value=${!n}
for ((i=1;i < $#;i++)) {
if [[ ${!i} == ${value} ]]; then # was == ${value}:*
echo "${!i}"
return 0
fi
}
echo
return 1
}
list=( 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 95 96 104 105 106 108 110 111 112 113 114 115 116 117 118 119 127 135 )
remaining=${#list[@]}
clear
echo 'Remaining ===>' ${list[@]}
xev | \
awk -W interactive '/state 0x.*, keycode / { print $4; fflush() }' | \
while read keycode; do
found=$(findInArray "${list[@]}" ${keycode})
if [[ $found ]]; then
clear
# Remove keycode from list
for i in ${!list[@]}; do
if [ "${list[$i]}" = $keycode ]; then
list[$i]=''
remaining=$((remaining-1));
fi
done
echo 'Remaining ===>' ${list[@]}
echo 'Remaining #' $remaining
if [[ $remaining == 0 ]]; then
clear
echo All keys successfully tested!
pkill xev
exit 0
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment