getkb
UPDATE: I used a variation of this in my "tinysh" script: https://www.mobileread.com/forums/sho...d.php?t=173657
Okay, I couldn't resist the diversion:
PHP Code:
#!/bin/sh
#===================================================
# getkb - get translated ascii keys from K3 keyboard
# v1.2 by geekmaster
# STDOUT: pressed keys, until Enter key pressed.
#---------------------------------------------------
# Copyright (C) 2012 geekmaster
# MIT License: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#---------------------------------------------------
DN=/dev/null
KN="1234567890____qwertyuiop____asdfghjkl_____zxcvbnm_."
KS="1234567890____QWERTYUIOP____ASDFGHJKL_____ZXCVBNM_,"
KP="1234567890____~@#$%^&*()____<>[]{}?/\_____;:'|-+=_?"
KM=$KN
killall -stop cvm launchpad 2>$DN
while :;do
L="_"
set $(waitforkey); K=$1 D=$2
[[ $D -eq 0 ]]&& continue
[[ $K -eq 28 ]]&& break # enter
[[ $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)"
echo -n "$L"
KM=$KN
done
echo ""
killall -cont cvm launchpad 2>$DN
Enjoy!
EDIT: For undefined keys, this inserts "(#)" into the STDOUT stream, where # is keycode number.
Combining this with eips for text, you could do a simple console. You would need to add support for special characters to be of much use though. You could use Menu, Home and Back keys as additional shifts, and copy and modify the KS string for the other Shift keys.
EDIT 2: Okay, now I added a bunch of symbols, using the "Sym" key as a symbol shift. They could probably use reorganizing, perhaps like the myts program uses. The missing keys would need special handling using "echo -e" to insert them (see the "eink algorithmic art shell scripting" thread for examples)... 
EDIT 3: This could be easily modified to work on the kindle DX, which uses different keycodes, by changing the contents of the "K" strings, and the keycode tests.
P.S. If you test this with SSH, it echos the keys immediately as they are pressed, and it exits after the Enter key is pressed on the kindle keyboard. To use in a script, you need to intercept the output like this: S="$(getkb)". You need the quotes or you will have a problem with the spacebar.
Also, you might want to output one character per line, so the calling script can use a "while ... read" loop to process individual keypresses. It would be simpler though to just have this script exit after each keypress, to be called again after the previous key is processed or displayed (perhaps with eips) -- but they you could have just used "waitforkey" yourself. I did it this way because that is the way it was specified in the request.