![]() |
#1 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#2 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#4 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#5 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#6 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
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.
|
![]() |
![]() |
![]() |
#7 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
![]() 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. |
![]() |
![]() |
![]() |
#8 |
Going Viral
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#9 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Now MIT licensed (also added to the code above).
![]() Last edited by geekmaster; 03-28-2012 at 10:43 PM. |
![]() |
![]() |
![]() |
#10 |
Going Viral
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#11 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#12 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#13 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
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? 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. |
|
![]() |
![]() |
![]() |
#14 |
Going Viral
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#15 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |