Keycodes

Program demonstrating an idea of how to read keycodes to figure out what button you want to trigger on. Mostly just a Proof Of Concept type thing, but might be useful to some people hacking on projects.

Source

import appuifw
import e32
import key_codes

"""Keycodes program: designed to make it possible, although probably not
easy, to find out what code a particular key has. Developed in part for 
wikipad. MIT License: Share and Enjoy."""

class Application:
    def __init__(self):
        self.lock = e32.Ao_lock()
        self.old_key = appuifw.app.exit_key_handler
        appuifw.app.exit_key_handler=self.exit
        appuifw.app.body = appuifw.Text(u"""To find key codes, press buttons. 
		This program probably won't do everything you need it to, but at least 
		it gives you a starting point.""")
        for i in dir(key_codes):
            try:
                appuifw.app.body.bind(getattr(key_codes,i),lambda i=i:self.print_i(i))
            except:
               pass
        self.lock.wait()
    def print_i(self, i):
        appuifw.note(u"%s"%i, "info")
    def exit(self):
        appuifw.app.exit_key_handler = self.old_key
        self.lock.signal()

A = Application()

Copyright 2003-2014, Christopher Schmidt