03-28-2012, 12:36 PM | #16 | |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
|
|
03-28-2012, 01:13 PM | #17 | |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
This is a significant contributing factor to why I prefer coding "on the bare metal". It is a lot of extra work to find sample code from which to borrow that is NOT bound by the GPL. I often have to go back to the basic research and thesis papers and write my own code directly from their base concepts. This gets interesting when there is a lot of difficult mathematics involved. In my commercial code, I add URLs and book references for where I got my information, to prove that it is not legally encumbered. I cannot include GPL references. Last edited by geekmaster; 03-28-2012 at 01:19 PM. |
|
Advert | |
|
03-28-2012, 02:52 PM | #18 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
|
03-28-2012, 03:09 PM | #19 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
My layman's guess is "yes", since many printed books are published under a pseudonym. For the prior musing... I have seen people just include a reference in their signature to their intended license. Something I often do myself is: License Name, <link>, included wherein by reference. (If you type small, you can get it on one line in the source. Which helps deal with the problem of the license text being longer than the code.) But I am not an attorney licensed to practice law, so readers of this thread should make their own decision (or hire a legal decision). |
|
03-28-2012, 03:10 PM | #20 |
Zealot
Posts: 130
Karma: 10000
Join Date: Mar 2012
Device: Kindle 3G, Kindle Touch 3G, iRiver Story HD, Sony Reader
|
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. |
Advert | |
|
03-28-2012, 03:37 PM | #21 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
One hint of something to check for in __any__ shell script -
The handling of whitespace. More correctly, the handling of the "Input Field Seperator" character(s). Often defined in the "IFS" variable and having the default of "space, tab, new-line" characters. I can read where G.M. has dealt with space and new-line. Perhaps tab (\x09) needs to be dealt with also? Since this code is a shell function, and since most shell implementations recognize a function local setting of IFS - Perhaps adding the pair of lines: local IFS IFS='some character you know will never show up in the key codes' Will aid in dealing with the whitespace issues. One hint about re-using G.M.'s function - It is a function. Add your code outside to the function and call the function from your added code passing the two expected parameters. If running this function under Bash or Bash's sh mode - You can pass any character (except \x00) by escaping it in the call. I.E: getkb $(printf '%q %q', parm-1, parm-2) That will properly escape the two parameters at the point of the call and Bash's function argument processing will un-escape them. For other sh implementations - a bit of experimenting might be required. |
03-28-2012, 03:39 PM | #22 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
http://tldp.org/LDP/abs/html/ |
|
03-28-2012, 04:37 PM | #23 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
@jmseight: The "killall" statements pause and resume the framework on my kindle, however some of the keypress events do remain in the keyboard input buffer so that after pressing Enter they show up in the search bar. I also had to pause the "launchpad" app I have running, or it "eats" spacebar presses.
I think there is a /proc to lock the keyboard for exclusive use, but that needs some research. The "myts" program locks the keyboard with with a C ioctl() call... I was thinking about using a buffer string and supporting the Del key later (like you did), but I needed to stop for sleep when I was writing that. Does "${ST%?}" work on the K3? A lot of other similar string processing that works on newer kindles does not work on the K3. [[ $K -eq 14 ]]&& ST="$(echo ${ST%?})" && continue # del For example, where I used ${ST:$K:1} on newer kindles I had to change to the older "echo|cut" for the K3 in this script. I will test the "%?" thing you did later when I get time... [[ $K -le 52 ]]&& L="$(echo \"$KM\"|cut -b$K-$K)" Question: Why are you using Aa for Enter? # [[ $K -eq 28 ]]&& break # enter [[ $K -eq 190 ]]&& break # use Aa for enter The spacebar (keycode 57) worked for me: [[ $K -eq 57 ]]&& L=" " # space I think that this is eating your space: ST="$(echo $ST$L)" When passing parameters that may contain spaces, you should wrap them in quotes like this: ST="$(echo \"$ST$L\")" In this case, the escaped quotes become part of the echo command, and they protect any trailing space that is contained in the expansion of $L. However in this particular case, why bother with an external command? Just do this instead: ST="$ST$L" Last edited by geekmaster; 03-28-2012 at 04:56 PM. |
03-28-2012, 05:02 PM | #24 | |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
About handling the tab key, well that would add complexity to my "one page" script, with code that would never get used (the K3 does not have a tab key). Of course, you can make it as complex as you want, if you want to. Just add your name to the credits so I do not get all the blame. Personally, before publishing, I like to strip out all unessential code, leaving only the elegant essence of the idea I am demonstrating... All the corner-case enhancements that add complexity ARE essential to some life-critical or mission-critical apps, but for demos or simple tools such as this, these safety features are better left out to aid understanding of the essential idea. IFS is one such unessential thing for here... Last edited by geekmaster; 03-28-2012 at 05:21 PM. |
|
03-28-2012, 05:04 PM | #25 |
Zealot
Posts: 130
Karma: 10000
Join Date: Mar 2012
Device: Kindle 3G, Kindle Touch 3G, iRiver Story HD, Sony Reader
|
Hi geekmaster,
Thank you for the hints. I am totally new at shell programming so am learning quite a bit from this. Thank you. Does "${ST%?}" work on the K3? A lot of other similar string processing that works on newer kindles does not work on the K3. >>>Yes. It works well. [[ $K -eq 14 ]]&& ST="$(echo ${ST%?})" && continue # del For example, where I used ${ST:$K:1} on newer kindles I had to change to the older "echo|cut" for the K3 in this script. I will test the "%?" thing you did later when I get time... [[ $K -le 52 ]]&& L="$(echo \"$KM\"|cut -b$K-$K)" Question: Why are you using Aa for Enter? # [[ $K -eq 28 ]]&& break # enter [[ $K -eq 190 ]]&& break # use Aa for enter >>> If I used enter, then the Kindle home screen actually does a search of what I typed, and sometimes an annoying dialog box comes up. I find that Aa is more graceful. The spacebar (keycode 57) worked for me: [[ $K -eq 57 ]]&& L=" " # space I think that this is eating your space: ST="$(echo $ST$L)" When passing parameters that may contain spaces, you should wrap them in quotes like this: ST="$(echo \"$ST$L\")" In this case, the escaped quotes become part of the echo command, and they protect any trailing space that is contained in the expansion of $L. However in this particular case, why bother with an external command? Just do this instead: ST="$ST$L" >>> Got it. I did not know you can do this. Best Regards, James |
03-28-2012, 05:11 PM | #26 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Yup, looks like it gets stripped:
Code:
core2quad $ sh $ ST="_ _" ; L=' ' ; ST="$ST$L" ; echo ${#ST} 4 $ ST="_ _" ; L=' ' ; ST="$(echo $ST$L)" ; echo ${#ST} 3 Use the %q format to printf rather than echo to return a string that might have a trailing IFS character. |
03-28-2012, 05:15 PM | #27 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
@G.M.
Not specifically to handle the "tab" key, but to handle the byte value \x09 as a keycode data value. |
03-28-2012, 05:19 PM | #28 |
Zealot
Posts: 130
Karma: 10000
Join Date: Mar 2012
Device: Kindle 3G, Kindle Touch 3G, iRiver Story HD, Sony Reader
|
Hi,
I tried ST="$ST$L" and whenever I hit the space things seems to get messed up so I cna no longer type anything else except Aa to terminate the script. The echo command ST="$(echo \"$ST$L\")" also does the same thing, except a lot of " signs are added to the string. Thanks, JAmes |
03-28-2012, 05:28 PM | #29 | |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
However, I just tried this on my K3: # ST="abcdefg" # L=" " # ST="$ST$L" # echo "($ST)" (abcdefg ) # Notice that the space was appended to ST as expected, so your problem must be in other code. Still, the quotes are needed to prevent chopping the trailing space off the string, like I said... After looking at your code again, I see another problem: eips $XP $YP $ST"_ " really should be: eips $XP $YP "$ST_ " Otherwise, a space in ST will expand the 3rd parameter into a 3rd and 4th parameter that will make eips unhappy, giving an error message to STDERR. In linux, parameters that may contain spaces MUST be enclosed in quotes. It's the law! Fear it! (Only leave out quotes when you know you can get away with it, like I do.) Last edited by geekmaster; 03-28-2012 at 05:35 PM. |
|
03-28-2012, 06:21 PM | #30 |
Zealot
Posts: 130
Karma: 10000
Join Date: Mar 2012
Device: Kindle 3G, Kindle Touch 3G, iRiver Story HD, Sony Reader
|
Yep. The problem is in the eips. Thanks for the great help.
The following works: eips $XP $YP "$ST""_ " I can use this to type commands into the shell, correct? eips 10 10 "Type command?" S="$(getkb 10 11)" sh < S Is the last statement correct? Thanks, James |
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
902 Have you tested the Bluetooth keyboard input? How fast is it? | firebelow | PocketBook | 5 | 04-11-2012 03:49 PM |
Need help on usbNetwork for K3G | everyday_kindle | Kindle Developer's Corner | 2 | 05-06-2011 09:00 AM |
K3g help | kmo101355 | Kindle Developer's Corner | 12 | 02-11-2011 10:18 AM |
Request An idea to use the e-ink display as keyboard input. | Leadlight | enTourage Archive | 6 | 05-30-2010 02:05 PM |
[Librie-Dev] better keyboard input for Librie "English" browsers | arivero | Legacy E-Book Devices | 1 | 08-15-2006 11:05 AM |