Hi Geekmaster,
Thank you very much for the code. I am trying to learn Linux script programming and this is very instructive, especially when I tried to modify it to do something a little different.
I noticed that any key pressed will be typed at the Kindle home screen as well. So typing and enter will cause a search to be performed. I substituted Aa as Enter.
I made some modification so it will display the string on the screen with a cursor and added the delete key.
I have not figured out how to get SPACE to work with this one.
BTW, is there a way to remove this behavior - so waitforkey does not type into the Kindle home screen?
Please see the below code - I am sure it can be optimized:
#!/bin/sh
#================================================= ==
# getkb - get translated ascii keys from K3 keyboard
# v1.2 by geekmaster
# STDOUT: pressed keys, until Enter key pressed.
#---------------------------------------------------
getkb() {
XP=$1
YP=$2
DN=/dev/null
KN="1234567890____qwertyuiop____asdfghjkl_____zxcv bnm_."
KS="1234567890____QWERTYUIOP____ASDFGHJKL_____ZXCV BNM_,"
KP="1234567890____~@#$%^&*()____<>[]{}?/\_____;:'|-+=_?"
KM=$KN
killall -stop cvm launchpad 2>$DN
ST=""
while :;do
eips $XP $YP $ST"_ "
L="_"
set $(waitforkey); K=$1 D=$2
[[ $D -eq 0 ]]&& continue
# [[ $K -eq 28 ]]&& break # enter
[[ $K -eq 190 ]]&& break # use Aa for enter
[[ $K -eq 14 ]]&& ST="$(echo ${ST%?})" && continue # del
[[ $K -eq 42 ]]&& KM=$KS && continue # shift
[[ $K -eq 126 ]]&& KM=$KP && continue # Sym
[[ $K -eq 57 ]]&& L=" " # space
[[ $K -le 52 ]]&& L="$(echo \"$KM\"|cut -b$K-$K)"
# [[ "$L" == "_" ]]&& L="($K)"
[[ "$L" == "_" ]]&& continue
# echo -n "$L"
ST="$(echo $ST$L)"
KM=$KN
done
echo "$ST"
echo ""
killall -cont cvm launchpad 2>$DN
}
Last edited by jmseight; 03-28-2012 at 03:27 PM.
|