![]() |
#31 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 32
Karma: 46558
Join Date: Feb 2012
Device: Kindle4NT
|
Is there any alternative to waitforkey which reads state of a key and goes further without waiting for key pressing?
|
![]() |
![]() |
![]() |
#32 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
![]() |
|
![]() |
![]() |
Advert | |
|
![]() |
#33 | |
Going Viral
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
What the copy of busybox does that you might be using may vary from the following, you just have to try it to find out. Every time you start a background job, that command __should__ return a "job id" number. Then you can do other things, and when ready to proceed with the result of the background job, do a "wait <job id>". Which will wait for the background job without the cpu overhead of a busy loop wait for the contents of /tmp/key to change. Where changes to /tmp/key is the expected result of the background job in this example case. |
|
![]() |
![]() |
![]() |
#34 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
But waiting for a keypress this way would stop the foreground process indefinately (until or if a key ever gets pressed). I am doing animation with regular frame updates, so that is not an option. I prefer completing my update cycle, then waiting for a timer event (in a blocking call) until time to begin the next update cycle. A simpler way than timer events is to sleep ALMOST until time to begin the new update cycle, then sync to the timer with a "busy loop" (a/k/a. spinlock). To conserve energy, you want to sleep as long as possible and busy-loop as short as possible. If you study video game source code, you will see that this is a very popular technique for controlling continuous interactive animation. This is what most of my demos do (see "usleep(K4DLY)"), which is followed in some code (removed from most published code for simplification) by a "while :;do" loop that calls my getmsec() function to continue at the exact millisecond to begin the next update cycle. Waiting for a keypress as you suggested can be done a lot easier than calling "wait" with the process ID. You could just call "waitforkey" after your updates are complete and you are ready to wait for a key press. There are useful reasons to use the "wait" function, but not using to convert a blocking waitforkey call (purposely forked to the background) BACK INTO a blocking waitforkey call is needless complicated, when you could have just called waitforkey in the foreground in the first place. Last edited by geekmaster; 04-25-2012 at 09:45 AM. |
|
![]() |
![]() |
![]() |
#35 | |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 32
Karma: 46558
Join Date: Feb 2012
Device: Kindle4NT
|
Quote:
![]() This code will be executing untill you press DOWN key: Code:
waitforkey 108 & W=$! while [[ $W == $(ps $W | grep $W | sed 's/pts.*//') ]] ; do ##some code## done ![]() |
|
![]() |
![]() |
Advert | |
|
![]() |
#36 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 58
Karma: 63518
Join Date: Apr 2012
Device: KT
|
|
![]() |
![]() |
![]() |
#37 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 124
Karma: 178472
Join Date: Jul 2012
Device: Kindle 4
|
would it be feasible to adapt this to take keyboard input from the ssh session that it was run from, rather than the kindle's keyboard (or my kindle 4's lack-of-keyboard)?
i don't know much linux but i googled and fiddled with the script using a "read" command, but that only takes a whole line of text at a time and doesn't show up on the kindle screen until you press enter. any way to grab individual keystrokes? |
![]() |
![]() |
![]() |
#38 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
There are some interesting ideas here:
http://www.etalabs.net/sh_tricks.html Especially the "reading input byte-by-byte" which claims that "dd" is the only thing guaranteed to read a single byte, and the inline piping trick. You might also need to mess with the IFS environment var. And where they show "od" you probably need to use "hexdump" instead. A good place to start anyway... |
![]() |
![]() |
![]() |
#39 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 124
Karma: 178472
Join Date: Jul 2012
Device: Kindle 4
|
thanks!
|
![]() |
![]() |
![]() |
#40 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
It would probably be easier to write a little C program to do a getch(), then print its number value, then exit. It could be compiled with the tcc (tinycc) package in another thread (see the tools index wiki). That new "getchar" program could be called from a script to fetch a single ascii character on STDIN.
But that "cheat" would take all the fun out of these scripts that use only built-ins. If you use C, you may as well draw to the framebuffer in C for much faster speed. My demo scripts are mostly for fun, like puzzle solving (but in a useful way). |
![]() |
![]() |
![]() |
#41 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 124
Karma: 178472
Join Date: Jul 2012
Device: Kindle 4
|
cool, thanks again. this is a neat little demo. all i really want is a terminal running on my k4's screen that i can control from my computer's keyboard, but the various terminal options don't play nicely on the k4 at this point. i'm not much of a coder myself, can sometimes hack things a little to get what i'm after, but not sure where's the best starting point for this.
|
![]() |
![]() |
![]() |
#42 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
For a terminal for the K4, you need an onscreen keyboard. Check out JoppyFur's thread that has a terminal for the K5. You could make a hybrid that uses K3 type keyboard processing to move a cursor around an onscreen keyboard like the K5 uses. You need to replace the touchscreen code with 5-way joystick code, but it can be done... Last edited by geekmaster; 08-06-2012 at 03:09 PM. |
|
![]() |
![]() |
![]() |
#43 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 124
Karma: 178472
Join Date: Jul 2012
Device: Kindle 4
|
yeah, would be good to have an onscreen keyboard as an option, but ideally i'd rather be able to use it remotely via my computer's real keyboard. basically setting the kindle up as a remote display for text editing and who knows what else.
|
![]() |
![]() |
![]() |
#44 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
VNC would be better for that.
|
![]() |
![]() |
![]() |
#45 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 124
Karma: 178472
Join Date: Jul 2012
Device: Kindle 4
|
that would be good too, but also currently doesn't run on k4
![]() |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help finding tiny towers and tiny zoo | mojkadona | Kindle Fire | 5 | 04-26-2012 07:02 PM |
Kindle onscreen keyboard shortcuts | Conniemartin | Amazon Kindle | 3 | 12-27-2011 02:59 PM |
Night Brothers - Vampire Thriller - 99 cents for a limited timefor a limited time | SidneyW | Self-Promotions by Authors and Publishers | 0 | 07-11-2011 09:49 AM |
Jointech JE100: any bigger onscreen keyboard? | datebtraveller | More E-Book Readers | 1 | 04-30-2010 06:33 AM |
PRS-500 Dictionary for Sony PRS500/5 (autorun from SD card) with onscreen keyboard | Clemenseken | Sony Reader Dev Corner | 3 | 07-05-2008 08:33 AM |