Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 03-27-2012, 02:51 AM   #1
jmseight
Zealot
jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'
 
Posts: 130
Karma: 10000
Join Date: Mar 2012
Device: Kindle 3G, Kindle Touch 3G, iRiver Story HD, Sony Reader
Shell script to wait for user input from K3g keyboard

Hi,

I am a new k3g user and not familiar with shell scripts. I installed kite on my k3d with usbnet, and changed the behavior of usbnet script so it displays "storage mode" or "ethernet mode" during the switch - so I know which mode it is going to. I used the eips shell command that I saw elsewhere.

I would like to ask if there is a shell command that will take input from the k3g keyboard - like INPUT in BASIC so it will wait for the user to type a string and be able to use the string in the rest of the script.

Thanks,
James
jmseight is offline   Reply With Quote
Old 03-27-2012, 05:57 AM   #2
hostar
Zealot
hostar is a glorious beacon of lighthostar is a glorious beacon of lighthostar is a glorious beacon of lighthostar is a glorious beacon of lighthostar is a glorious beacon of lighthostar is a glorious beacon of lighthostar is a glorious beacon of lighthostar is a glorious beacon of lighthostar is a glorious beacon of lighthostar is a glorious beacon of lighthostar is a glorious beacon of light
 
Posts: 138
Karma: 12324
Join Date: Dec 2011
Location: CZ
Device: Kindle 4 non-touch
In bash it is command "read".

See example here:
http://tldp.org/LDP/Bash-Beginners-G...ect_08_02.html
hostar is offline   Reply With Quote
Old 03-27-2012, 08:07 AM   #3
hawhill
Wizard
hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.
 
hawhill's Avatar
 
Posts: 1,379
Karma: 2155307
Join Date: Nov 2010
Location: Goettingen, Germany
Device: Kindle Paperwhite, Kobo Mini
I think jmseight is talking about something that does not rely on a terminal emulator, though. Note that scripts run by kite won't have a TTY they can read from. Rather, something like "xdialog" or similar would be needed.

I'm not aware of such a program for now. OTOH, it wouldn't be that hard to program. In fact, - shameless plug - kindlepdfreader's Lua code could easily be modified to work that way (it already has an implementation of an input box). However, that would be somewhat overkill, since PDF and DJVU libraries are included.

So for now, combining hostar's advice with running a terminal program (like myts) is probably the way to go.
hawhill is offline   Reply With Quote
Old 03-27-2012, 08:38 AM   #4
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
The kindles have a "waitforkey" command. It returns the same keycodes used by the launchpad app (and can be used to find keycodes to use in it).

On the kindle DX/K3/K4 it returns keycodes for the buttons on the sides too, in addition to the "keyboard" keys. On the Touch it also returns keycodes for touchscreen and accelerometer (rotation) events (so picking up your kindle touch can cause a script to continue when sitting at a "Press any key to continue . . ." prompt.

You can use "waitforkey" in script files. For testing a lot of keys, I like to do this from SSH:

while :;do waitforkey;done

Last edited by geekmaster; 03-27-2012 at 10:10 PM.
geekmaster is offline   Reply With Quote
Old 03-27-2012, 11:19 PM   #5
jmseight
Zealot
jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'jmseight knows the difference between 'who' and 'whom'
 
Posts: 130
Karma: 10000
Join Date: Mar 2012
Device: Kindle 3G, Kindle Touch 3G, iRiver Story HD, Sony Reader
Hi,

Thank you for your responses.

What I am looking is for the user to type an entire string and hit enter, and the string will be returned. waitforkey will return one key, correct?

Thanks,
James
jmseight is offline   Reply With Quote
Old 03-27-2012, 11:43 PM   #6
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Quote:
Originally Posted by jmseight View Post
Hi,

Thank you for your responses.

What I am looking is for the user to type an entire string and hit enter, and the string will be returned. waitforkey will return one key, correct?

Thanks,
James
Yes, but you could write a script that converts keycodes to letters and appends them to a string, then exits when it sees the enter key.
geekmaster is offline   Reply With Quote
Old 03-28-2012, 01:23 AM   #7
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3


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 -"$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.


Last edited by geekmaster; 03-29-2012 at 08:11 PM.
geekmaster is offline   Reply With Quote
Old 03-28-2012, 06:51 AM   #8
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Answered.

Last edited by knc1; 03-28-2012 at 02:44 PM.
knc1 is offline   Reply With Quote
Old 03-28-2012, 09:29 AM   #9
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Quote:
Originally Posted by knc1 View Post
What license is this published under?
Now MIT licensed (also added to the code above).

Last edited by geekmaster; 03-28-2012 at 10:43 PM.
geekmaster is offline   Reply With Quote
Old 03-28-2012, 11:00 AM   #10
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA

Last edited by knc1; 03-28-2012 at 02:45 PM.
knc1 is offline   Reply With Quote
Old 03-28-2012, 11:14 AM   #11
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Now MIT licensed. (Off-topic licensing heated debate removed.)

Last edited by geekmaster; 03-28-2012 at 10:44 PM.
geekmaster is offline   Reply With Quote
Old 03-28-2012, 11:43 AM   #12
hawhill
Wizard
hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.
 
hawhill's Avatar
 
Posts: 1,379
Karma: 2155307
Join Date: Nov 2010
Location: Goettingen, Germany
Device: Kindle Paperwhite, Kobo Mini
Aye, I guess you two should really have a beer once ;-) There's a strange tendency between both of you to misunderstand each others deeper intentions, I think... verbosity interpreted as distraction, humour interpreted as indecency, brevity as being harsh, concern as insistence...

Back to the (intermediate) topic: I do share your attitude towards licences for "short snippets", geekmaster. However, in my country there is neither a "fair use" exemption, nor is there the possibility of giving to the "Public Domain", mainly due to the missing possibility to deny all warranty (you cannot opt out for being responsible up to the same point as you can in anglo-american law). So: some of us are unfortunately burdened with having to be a lot more concerned about legal stuff.

As an aside note: You might have noticed that I'm always mentioning the licence prominently. That's not because I'm a GPL zealot. Not the least, in fact, I much more like the PD! But in my legal environment, those things are unfortunately mandatory. Well, yes, and then I am still a law student (besides working in a library), so that may also contribute to be extra careful here ;-)

I really hope that my diplomatic interventions are not annoying. Please tell me if they are.
hawhill is offline   Reply With Quote
Old 03-28-2012, 11:50 AM   #13
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Quote:
Originally Posted by hawhill View Post
I really hope that my diplomatic interventions are not annoying. Please tell me if they are.
Interesting, informative, and welcome!

I use open-source in commercial projects, so I am fond of MIT, BSD, CPOL, and similar licenses so I do not have to use DLLs. I *do* use LGPL occasionally, such as the tinycc DLL and the SDL 1.2 DLL, which are LGPL and allow dynamic linking to commercial projects, but it is an annoyance.

What license do you recommend, so that I (and others) can reuse my code in commercial projects?
http://www.codinghorror.com/blog/2007/04/pick-a-license-any-license.html
The license shown above reportedly belongs to an atomic power plant in Moscow.

EDIT: I added the MIT license to the above script. I suppose I need to add it to my other published scripts and C programs now... And for that matter, is it even a LEGAL license if the copyright holder is identified by a pseudonym?

Last edited by geekmaster; 08-06-2012 at 07:59 PM.
geekmaster is offline   Reply With Quote
Old 03-28-2012, 12:05 PM   #14
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
For authors in the US, published in the US, my own personal preference is:
http://www.opensource.org/licenses/mit-license.html

Last edited by knc1; 03-28-2012 at 02:47 PM.
knc1 is offline   Reply With Quote
Old 03-28-2012, 12:08 PM   #15
hawhill
Wizard
hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.hawhill ought to be getting tired of karma fortunes by now.
 
hawhill's Avatar
 
Posts: 1,379
Karma: 2155307
Join Date: Nov 2010
Location: Goettingen, Germany
Device: Kindle Paperwhite, Kobo Mini
@geekmaster: Oh, PD is fine if _you_ use it :-) It's just that our legislation doesn't allow _me_ to license my stuff under it. While not directed at software, the CreativeCommons initiative has done a great job to try and "translate" a set of license to lots of legal environments. They have created something "as near as possible" to Public Domain for their CC0 license for Germany, for example.

When I get funny, I create something like my "know-what-your're-doing-license", which you can find e.g. here: http://cccgoe.de/wiki/2wiki.sh (it features a bash script that facilitates uploading images into a MediaWiki, it's been a two-hour "distraction project" of mine since a friend whished to be able to upload images from his N900 phone that can trigger scripts upon taking images.

But in general, I much prefer good old MIT/BSD. I'm still a believer in the greater good, and do have some vague anarchist ideals, so I'm not too fond of the whole GPL thing. I have made some "bad" experiences, too: this Android app http://www.androlib.com/android.appl...ader-npFE.aspx is something that I created and open-sourced (later versions with some help of another person). Someone went on and started to sell it for money on the Google Market - well, that was not my intention. But the GPL does not prevent that. Well, it would have enforced better credit than that guy gave, but it doesn't prevent anyone from selling your software that you intended to give away for free. I was thinking about creating my own licence that excluded commercial distribution. But this would be a minefield in a lot of legislations, too.

In most cases, however, using third-party software will force me into the GPL one way or another. So lots of things I write end up being GPL.
hawhill is offline   Reply With Quote
Reply


Forum Jump

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


All times are GMT -4. The time now is 12:36 AM.


MobileRead.com is a privately owned, operated and funded community.