This forum has been archived. All content is frozen. Please use KDE Discuss instead.

script displaying key number when key is pressed.

0

Votes
0
0
Tags: keyboard, scripting, keys pressed, mouse button pressed, key detection keyboard, scripting, keys pressed, mouse button pressed, key detection keyboard, scripting, keys pressed, mouse button pressed, key detection
(comma "," separated)
User avatar
jeshu
Registered Member
Posts
3
Karma
0
It can be frustrating to remember all the key numbers when scripting. This handy little script displays the key numbers when key is pressed.

Code: Select all
#!/bin/bash

IFS=$'\t\n'
keyId=`xinput --list --long | grep XIKeyClass | head -n 1 | egrep -o '[0-10]+'`;sleep .21;MouseId=`xinput --list --long | grep XIButtonClass | head -n 1 | egrep -o '[0-9]+'`;
echo "keyId="$keyId
echo "MouseId="$MouseId
IFS=$' \t\n'
rest=.07 #.14
rest2=.07 #.14

i2=16;i3=32;i4=48;i5=64;i6=80;i7=96;i8=112;i9=128;i10=144;i11=160;i12=176;i13=192;i14=208;i15=224;i16=240;i17=256
while :;do STATE2=$(xinput --query-state $keyId );STATE1=$(xinput --query-state $MouseId );if ! [ "$STATE2" = "$STATE3" ]; then for i in `seq 1  16`;do STATE3=$STATE2;if [[ $STATE2 == *"key[$i]=down"* ]]; then if [ $(( i )) = 9 ];then echo "Esc key number="$(( i ));else echo " key number="$(( i ));fi;break;elif [[ $STATE2 == *"key[$(( i2 + i ))]=down"* ]];then if [ $(( i2 + i )) = 22 ];then echo "Back Space key number="$(( i2 + i ));elif [ $(( i2 + i )) = 23 ];then echo "Tab key number="$(( i2 + i ));else echo " key number="$(( i2 + i ));fi;break;elif [[ $STATE2 == *"key[$(( i3 + i ))]=down"* ]]; then if [ $(( i3 + i )) = 36 ];then echo "Enter key number="$(( i3 + i ));elif [ $(( i3 + i )) = 37 ];then echo "Left Ctrl key number="$(( i3 + i ));else echo " key number="$(( i3 + i ));fi;break;elif [[ $STATE2 == *"key[$(( i4 + i ))]=down"* ]]; then if [ $(( i4 + i )) = 62 ] ;then echo "Right Shift key number="$(( i4 + i )) ;elif [ $(( i4 + i )) = 64 ] ;then echo "Left Alt key number="$(( i4 + i )) ;elif [ $(( i4 + i )) = 50 ] ;then echo "Left Shift key number="$(( i4 + i ));elif [ $(( i4 + i )) = 49 ] ;then echo "Acute key number="$(( i4 + i ));else echo " key number="$(( i4 + i ));fi;break;elif [[ $STATE2 == *"key[$(( i5 + i ))]=down"* ]]; then if [ $(( i5 + i )) = 65 ] ;then echo "Space key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 66 ] ;then echo "CapsLock key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 67 ] ;then echo "  F1 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 68 ] ;then echo "  F2 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 69 ] ;then echo "  F3 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 70 ] ;then echo "  F4 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 71 ] ;then echo "  F5 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 72 ] ;then echo "  F6 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 73 ] ;then echo "  F7 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 74 ] ;then echo "  F8 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 75 ] ;then echo "  F9 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 76 ] ;then echo "  F10 key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 78 ] ;then echo "  ScrLk key number="$(( i5 + i )) ;elif [ $(( i5 + i )) = 77 ] ;then echo "  NmLk key number="$(( i5 + i )) ;else echo " key number="$(( i5  + i ));fi;break;elif [[ $STATE2 == *"key[$(( i6 + i ))]=down"* ]] ; then if [ $(( i6 + i )) = 95 ] ;then echo "  F11 key number="$(( i6 + i )) ;elif [ $(( i6 + i )) = 96 ] ;then echo "  F12 key number="$(( i6 + i )) ;fi;break;elif [[ $STATE2 == *"key[$(( i7 + i ))]=down"* ]]; then   if [ $(( i7 + i )) = 108 ] ;then echo "Right Alt key number="$(( i7 + i )) ;elif [ $(( i7 + i )) = 105 ] ;then echo "Right Ctrl key number="$(( i7 + i ));elif [ $(( i7 + i )) = 104 ] ;then echo "Enter key number="$(( i7 + i ));elif [ $(( i7 + i )) = 110 ] ;then echo "  Home key number="$(( i7 + i ));elif [ $(( i7 + i )) = 112 ] ;then echo "  PgUp key number="$(( i7 + i ));elif [ $(( i7 + i )) = 111 ] ;then echo "  Up Arrow key number="$(( i7 + i ));elif [ $(( i7 + i )) = 107 ] ;then echo "PrtSc key number="$(( i7 + i )) ;else echo " key number="$(( i7  + i ));fi;break;elif [[ $STATE2 == *"key[$(( i8 + i ))]=down"* ]]; then if [ $(( i8 + i )) = 117 ] ;then echo "  PgDn key number="$(( i8 + i )) ;elif [ $(( i8 + i )) = 119 ] ;then echo "  Delete key number="$(( i8 + i ));elif [ $(( i8 + i )) = 113 ] ;then echo "  Left Arrow key number="$(( i8 + i ));elif [ $(( i8 + i )) = 114 ] ;then echo "  Right Arrow key number="$(( i8 + i ));elif [ $(( i8 + i )) = 115 ] ;then echo "  End key number="$(( i8 + i ));elif [ $(( i8 + i )) = 116 ] ;then echo "  Down Arrow key number="$(( i8 + i ));elif [ $(( i8 + i )) = 127 ] ;then echo "Pause key number="$(( i8 + i )) ;elif [ $(( i8 + i )) = 118 ];then echo "Insert key number="$(( i8 + i )) ;else echo " key number="$(( i8  + i ));fi;break;elif [[ $STATE2 == *"key[$(( i9 + i ))]=down"* ]] ; then if [ $(( i9 + i )) = 133 ] ;then echo "Windows key number="$(( i9 + i )) ;elif [ $(( i9 + i )) = 135 ] ;then echo "Right Click key number="$(( i9 + i )) ;else echo " key number="$(( i9  + i ));fi;break;elif [[ $STATE2 == *"key[$(( i10 + i ))]=down"* ]] ; then echo " key number="$(( i10 + i ));break;elif [[ $STATE2 == *"key[$(( i11 + i ))]=down"* ]] ; then echo " key number="$(( i11 + i ));break;elif [[ $STATE2 == *"key[$(( i12 + i ))]=down"* ]] ; then echo " key number="$(( i12 + i ));break;elif [[ $STATE2 == *"key[$(( i13 + i ))]=down"* ]] ; then echo " key number="$(( i13 + i ));break;elif [[ $STATE2 == *"key[$(( i14 + i ))]=down"* ]] ; then echo " key number="$(( i14 + i ));break;elif [[ $STATE2 == *"key[$(( i15 + i ))]=down"* ]] ; then echo " key number="$(( i15 + i ));break;elif [[ $STATE2 == *"key[$(( i16 + i ))]=down"* ]] ; then echo " key number="$(( i16 + i ));break;elif [[ $STATE2 == *"key[$(( i17 + i ))]=down"* ]] ; then echo " key number="$(( i17 + i ));break;fi;done;rest2=.0004;elif ! [ "$STATE1" = "$STATE4" ] ; then STATE4=$STATE1;for i in `seq 1  10`;do if [[ $STATE1 == *"button[$i]=down"* ]] ; then   echo " button number "$i" has been clicked";break;fi;done;else rest2=.033;fi;done


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]