modification.sh (9493B)
1 #!/bin/bash 2 function keychar { 3 parin1=$1 #first param; abc1 4 parin2=$2 #second param; 0=a, 1=b, 2=c, 3=1, 4=a, ... 5 parin2=$((parin2)) #convert to numeric 6 parin1len=${#parin1} #length of parin1 7 parin2pos=$((parin2 % parin1len)) #position mod 8 char=${parin1:parin2pos:1} #char key to simulate 9 if [ "$parin2" -gt 0 ]; then #if same key pressed multiple times, delete previous char; write a, delete a write b, delete b write c, ... 10 xdotool key "BackSpace" 11 fi 12 #special cases for xdotool ( X Keysyms ) 13 if [ "$char" = " " ]; then char="space"; fi 14 if [ "$char" = "." ]; then char="period"; fi 15 if [ "$char" = "-" ]; then char="minus"; fi 16 xdotool key $char 17 } 18 datlastkey=$(date +%s%N) 19 strlastkey="" 20 intkeychar=0 21 intmsbetweenkeys=500 #two presses of a key sooner that this makes it delete previous key and write the next one (a->b->c->1->a->...) 22 intmousestartspeed=15 #mouse starts moving at this speed (pixels per key press) 23 intmouseacc=0 #added to the mouse speed for each key press (while holding down key, more key presses are sent from the remote) 24 intmousespeed=15 25 switch=0 26 browser=/etc/alternatives/x-www-browser 27 test -e /usr/bin/firefox && browser=firefox 28 test -e /usr/bin/chromium-browser && browser=chromium-browser 29 30 31 while read oneline 32 do 33 keyline=$(echo $oneline | grep " key ") 34 #echo $keyline --- debugAllLines 35 if [ -n "$keyline" ]; then 36 datnow=$(date +%s%N) 37 datdiff=$((($datnow - $datlastkey) / 1000000)) #bla bla key pressed: previous channel (123) 38 strkey=$(grep -oP '(?<=sed: ).*?(?= \()' <<< "$keyline") #bla bla key pres-->sed: >>previous channel<< (<--123) 39 strstat=$(grep -oP '(?<=key ).*?(?=:)' <<< "$keyline") #bla bla -->key >>pressed<<:<-- previous channel (123) 40 strpressed=$(echo $strstat | grep "pressed") 41 strreleased=$(echo $strstat | grep "released") 42 if [ -n "$strpressed" ]; then 43 #echo $keyline --- debug 44 if [ "$strkey" = "$strlastkey" ] && [ "$datdiff" -lt "$intmsbetweenkeys" ]; then 45 intkeychar=$((intkeychar + 1)) #same key pressed for a different char 46 intmousespeed=100 47 else 48 intkeychar=0 #different key / too far apart 49 fi 50 datlastkey=$datnow 51 strlastkey=$strkey 52 case "$strkey" in 53 "1") 54 xdotool mousemove 270 154 55 ;; 56 "2") 57 xdotool mousemove 679 154 58 ;; 59 "3") 60 xdotool mousemove 1090 154 61 ;; 62 "4") 63 xdotool mousemove 270 382 64 ;; 65 "5") 66 xdotool mousemove 679 382 67 ;; 68 "6") 69 xdotool mousemove 1090 382 70 ;; 71 "7") 72 xdotool mousemove 270 604 73 ;; 74 "8") 75 xdotool mousemove 679 604 76 ;; 77 "9") 78 xdotool mousemove 1090 604 79 ;; 80 "0") 81 xdotool key Prior 82 ;; 83 "previous channel") 84 xdotool key Space #Enter 85 ;; 86 "channel up") 87 xdotool click 4 #mouse scroll up 88 ;; 89 "channel down") 90 xdotool click 5 #mouse scroll down 91 ;; 92 "channels list") 93 xdotool click 3 #right mouse button click" 94 ;; 95 "up") 96 xgm=$(xdotool getmouselocation --shell | grep Y | sed -e s/^..// ) 97 intpixels=$((-1 * intmousespeed * 2)) 98 test $switch -eq 1 && xdotool key Up || xdotool mousemove_relative -- 0 $intpixels #move mouse up 99 intmousespeed=$((intmousespeed + intmouseacc)) #speed up 100 test $xgm$(xdotool getmouselocation --shell | grep Y | sed -e 's/^..//' ) -eq 00 && xdotool mousemove_relative -- 0 768 101 ;; 102 "down") 103 xgm=$(xdotool getmouselocation --shell | grep Y | sed -e s/^..// ) 104 intpixels=$(( 1 * intmousespeed)) 105 test $switch -eq 1 && xdotool key Down || xdotool mousemove_relative -- 0 $intpixels #move mouse down 106 intmousespeed=$((intmousespeed + intmouseacc)) #speed up 107 test $xgm$(xdotool getmouselocation --shell | grep Y | sed -e 's/^..//' ) -eq 767767 && xdotool mousemove_relative -- 0 -768 108 ;; 109 "left") 110 xgm=$(xdotool getmouselocation --shell | grep X | sed -e s/^..// ) 111 intpixels=$((-1 * intmousespeed * 2 )) 112 test $switch -eq 1 && xdotool key Left || xdotool mousemove_relative -- $intpixels 0 #move mouse left 113 intmousespeed=$((intmousespeed + intmouseacc)) #speed up 114 test $xgm$(xdotool getmouselocation --shell | grep X | sed -e 's/^..//' ) -eq 00 && xdotool mousemove_relative -- 1359 0 115 ;; 116 "right") 117 xgm=$(xdotool getmouselocation --shell | grep X | sed -e s/^..// ) 118 intpixels=$(( 1 * intmousespeed)) 119 test $switch -eq 1 && xdotool key Right || xdotool mousemove_relative -- $intpixels 0 #move mouse right 120 intmousespeed=$((intmousespeed + intmouseacc)) #speed up 121 test $xgm$(xdotool getmouselocation --shell | grep X | sed -e 's/^..//' ) -eq 13591359 && xdotool mousemove_relative -- -1359 0 122 ;; 123 "select") 124 test $switch -eq 1 && xdotool key Return || xdotool click 1 #left mouse button click 125 ;; 126 "return") 127 #xdotool key "Alt_L+Left" #WWW-Back 128 ((switch++)) 129 test $switch -eq 2 && switch=0 130 ;; 131 "exit") 132 ((switch++)) 133 test $switch -eq 2 && switch=0 134 ;; 135 "F2") 136 ((menu++)) 137 xdotool key Escape 138 test $menu -eq 1 && xdotool click 3 || xdotool key Super_L 139 test $menu -eq 2 && menu=0 140 switch=1 141 ;; 142 "F3") 143 $browser & 144 ;; 145 "F4") 146 ((xvkbd++)) 147 switch=0 148 xdotool mousemove 1100 750 149 xvkbd -no-keypad -geometry +905+560 & 150 test $xvkbd -eq 2 && killall xvkbd && xvkbd=0 151 ;; 152 "F1") 153 #chromium-browser --incognito "https://www.google.com" & 154 /etc/alternatives/x-terminal-emulator & 155 ((xvkbd++)) 156 switch=0 157 xdotool mousemove 1170 760 158 xvkbd -no-keypad -geometry +905+560 & 159 test $xvkbd -eq 2 && killall xvkbd && xvkbd=0 160 161 ;; 162 "rewind") 163 $browser & 164 ;; 165 "pause") 166 ((menu++)) 167 xdotool key Escape 168 test $menu -eq 1 && xdotool click 3 || xdotool key Super_L 169 test $menu -eq 2 && menu=0 170 switch=1 171 ;; 172 "Fast forward") 173 /etc/alternatives/x-terminal-emulator & 174 ((xvkbd++)) 175 switch=0 176 xdotool mousemove 1170 660 177 xvkbd -no-keypad -geometry +905+560 & 178 test $xvkbd -eq 2 && killall xvkbd && xvkbd=0 179 ;; 180 "play") 181 ((xvkbd++)) 182 switch=0 183 xdotool mousemove 1100 750 184 xvkbd -no-keypad -geometry +905+560 & 185 test $xvkbd -eq 2 && killall xvkbd && xvkbd=0 186 187 ;; 188 "stop") 189 ## with my remote I only got "STOP" as key released (auto-released), not as key pressed; see below 190 echo Key Pressed: STOP 191 ;; 192 *) 193 echo Unrecognized Key Pressed: $strkey ; CEC Line: $keyline 194 ;; 195 196 esac 197 fi 198 if [ -n "$strreleased" ]; then 199 #echo $keyline --- debug 200 case "$strkey" in 201 "stop") 202 xdotool key q 203 xdotool key Control_L+Next 204 ;; 205 "up") 206 intmousespeed=$intmousestartspeed #reset mouse speed 207 ;; 208 "down") 209 intmousespeed=$intmousestartspeed #reset mouse speed 210 ;; 211 "left") 212 intmousespeed=$intmousestartspeed #reset mouse speed 213 ;; 214 "right") 215 intmousespeed=$intmousestartspeed #reset mouse speed 216 ;; 217 esac 218 fi 219 fi 220 done