scripts-reco

Des scripts pour faciliter le reconditionnement de portables - retour accueil

git clone git://bebou.netlib.re/scripts-reco

Log | Files | Refs | README |

clavier (1150B)


      1 # Clavier
      2 pause "Il va falloir appuyer sur toutes les touches du clavier de gauche à droite, de haut en bas"
      3 
      4 update_layout() {
      5 	[ -f "$tmpdir/kbd_valid" ] && regex="$(< $tmpdir/kbd_valid paste -s -d '|' -)" || regex="^$"
      6 	< "$disposition" awk "/$regex/ {printf \"%s%s%s\n\",\"$vert\",\$0,\"$norm\";next}1" |
      7 		paste - - - |
      8 		column -ts '	'
      9 }
     10 
     11 launch_xev() {
     12 	stdbuf -i0 -o0 xev | $awk_inter '
     13 		/^Key(Press|Release)/ {type=$1}
     14 		/keycode [0-9]+/ && !(NR%2) {print substr($7,0,index($7,")")-1)}' > $tmpdir/kbd_fifo&
     15 	awk_pid=$!
     16 }
     17 
     18 command -V mawk > /dev/null && awk_inter="mawk -W interactive" || awk_inter="stdbuf -i0 -o0 gawk"
     19 
     20 disposition=$(find clavier -type f -name '*.kbd' | fzy)
     21 [ ! -p "$tmpdir/kbd_fifo" ] && mkfifo $tmpdir/kbd_fifo
     22 
     23 launch_xev
     24 
     25 while read key;do
     26 	clear;update_layout;
     27 	if ! ps -q "$awk_pid" > /dev/null;then
     28 		launch_xev
     29 	fi
     30 	printf "verification de $key, ligne $i\n"
     31 	while read entered;do
     32 		if [ "$entered" = "$key" ];then
     33 			printf "^%s$\n" "$key" >> $tmpdir/kbd_valid;break
     34 		else
     35 			printf "reçu : %s, voulu : %s\n" "$entered" "$key"
     36 		fi
     37 	done < $tmpdir/kbd_fifo
     38 done < "$disposition"
     39 
     40 clear
     41 update_layout | sauver