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 Today, 04:45 PM   #1
kdusr
Connoisseur
kdusr began at the beginning.
 
kdusr's Avatar
 
Posts: 78
Karma: 13
Join Date: Oct 2016
Location: Mars
Device: KOA, KV, KOA2,PW4,PW5
Smile capture KO2 physical button event

My KO2 jailbreaked, I installed Python on the KO2, currently I am working on a Python TK(tkinter) App for the KO2.

I want to use KO2 physical button to trigger something on my App, but python TK can not capture the event of the physical buttons on KO2,
my testing python script as follows (py_tk_event_test.py) :
Code:
import Tkinter as tk

def hotkey_manager(event):
    key = event.keysym
    key_chr = event.char
    key_code = event.keycode
    mouse_button = event.num    # mouse button index
    typ = event.type

    print(key, key_chr, key_code,  mouse_button, typ)
    if key.lower() == 'next': print('---page dw---')     #if page down key is clicked , print "page dw"
    if key.lower() == 'prior': print('---page up---')    #if page up key is clicked , print "page up"

def tk_event_test():
    root = tk.Tk()
    root.title('L:A_N:dialog_ID:TkSide0')   #set win title for kindle sys

    button_test = tk.Button(text='Close', height=4, width=30, font=("Sans", '12', 'bold'), command=(root.destroy))
    button_test.pack()  # create TK button

    root.bind('<Button-1>', hotkey_manager)   #bind mouse left button to TK UI
    root.bind('<KeyPress>', hotkey_manager)   #bind anykey press to TK UI (to show test reaction)

    root.mainloop()   #launch UI
tk_event_test()
The Python script bind anykey press event to the TK UI, when the UI is launched, press anykey on the keyboard, it prints out the key name, key char, key hex code, event type info. when I run the python script on my linux laptop, it works fine as I expect:
#press 'a' on the keyboard
('a', 'a', 38, '??', '2')

#press 'b' on the keyboard
('b', 'b', 56, '??', '2')

#Press 'page-up' on the keyboard
('Prior', '', 112, '??', '2')
---page up---

#Press 'Page-down' on the keyboard
('Next', '', 117, '??', '2')
---Page down---

#Press mouse button 1 (left mouse button)
('??', '??', '??', 1, '4')


Launch the python TK UI on KO2 (the UI only contains one "Close" button):

But when I run the Python script on Kindle KO2, the script can not capture any keyboard event, only the mouse button-1 event (single click on the touchscreen) can be captured.
I press the KO2 physical button, there is no feedback from my python script,
When I click touchscreen on the "Close" button, I get mouse event feedback as follows:
('??', '??', '??', 1, '4')

The interesting thing is that the Python script on Kindle cannot capture the physical button event, but I can see unexceptional feedback in the terminal when I press physical button( page-up, page-down) , get something like this
#press the KO2 physical button "page-up":
^[[5~
#Press the KO2 physical button "page down":
^[[6~


repeat press the page-down button two more times:


the mouse event can be captured (single click "Close" button on the touchscreen, quit from the TK UI):



I searched in Google, “^[[5~” and “^[[6~” are some kind of key code for "page-up" and "page-down".
When I click the terminal's on-screen keyboard "page-up" and "page-down" key, I get the same rustle:
^[[5~ ^[[6~

This terminal feedback only happens after I run my Python script,
So at least the terminal can capture the KO2 physics button event,
then I use the "dmesg" command to list all the events triggered on the KO2.
dmesg | grep keys
#the last 4 rows as follows:
[5782.691165] gpio_keys_gpio_report_event: type=1, code=104, state=1
[5791.110264] gpio_keys_gpio_report_event: type=1, code=109, state=1
[5795.610269] gpio_keys_gpio_report_event: type=1, code=109, state=1
[5799.202911] gpio_keys_gpio_report_event: type=1, code=109, state=1
I think the "gpio_keys code=104" is page-up, the "gpio_keys code=109" is page-down.

Speculate and question:
there is no keyboard module (or driver) on the kindle, the gpio_keys physical button is simulated as "page-up" and "page-down" key, it is not a real keyboard event.
I guess this is the main reason why Python TK cannot capture the physical button event.

The question is: how to capture this gpio_keys physical button event,
If it is not easy to implement in Python, how to capture it in C?

Thank you for reading my post, I appreciate your reply.

Last edited by kdusr; Today at 04:51 PM.
kdusr is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hardware about capture hardware page up(down) button event? kdusr Kindle Developer's Corner 5 12-13-2018 02:10 PM
K5 Physical home button Cinisajoy Kindle Developer's Corner 0 08-21-2015 12:09 PM
[Help] Kindle Touch - Any apps/function could replace dead physical Home button? vankhoa Kindle Developer's Corner 4 11-24-2013 01:11 PM
The Menu (physical) button is your friend! sarah11918 enTourage Archive 0 04-15-2010 11:39 AM
iLiad non-GTK+ apps not getting button event from X ericshliao iRex Developer's Corner 7 08-30-2009 06:52 AM


All times are GMT -4. The time now is 07:15 PM.


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