View Single Post
Old 04-29-2012, 07:04 PM   #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 kiri87 View Post
As you may have noticed, I added launchpad actions to start/quit the app, and it _does_ work properly as a screensaver. I didn't touch the code, though. And doing an update every second eats up the battery quite fast.

I'm new to Linux programming. How do I check the the "pressed" state of a key, so I can break out of a for ( ; ; ) loop?
The simplest way (which can also be done from a script) is to launch the "waitforkey" program in the background and pipe its output to a temp file. You can either tell it to wait for a specific key and call "ps|grep" (with other parameters) to check for it to quit after it sees the key it is waiting for (default ANY key). Or you can periodically check the output file for a pressed key code. Details were provided in another thread.

A more "correct" way is to process the input device events for the keyboard and/or other devices (like touch screen). I have an unfinished script that does a pretty good job of processing raw binary input device events using hexdump, for both keys and touchscreen.

The nice thing about "waitforkey" is that is returns key codes for other events too, like touchscreen (one or two fingers touching, or touch PLUS home key), and even rotation events are returned as pressed keys by waitforkey. And by the way, even though most input devices are turned off when asleep (screensaver mode), waitforkey returns rotation events while asleep. That way a background program can wake the kindle when it is picked up (and rotated enough to trigger a rotation event).
geekmaster is offline   Reply With Quote