| Reply | « Previous Thread | Next Thread » |
|
Hey,
I'm trying to write an SMS composer that captures key events. I have written two independent programs but I'm having trouble integrating them. For the key event program, I'm setting the the following: Code:
canvas = appuifw.Canvas(redraw_callback = redraw_callback,
event_callback = event_callback)
appuifw.app.body = canvas
Code:
appuifw.app.body = appuifw.Text() Many Thanks, A |
|
Hi,
you have to write your own separate method for getting key value, while any key is pressed and you have to find it out which key is pressed by the user. Hope this may be help. Pavan Pareta http://www.croozeus.com/started.htm |
| pavan.pareta |
| View Public Profile |
| Find all posts by pavan.pareta |
|
The method I was using was a callback function. I have appended the full code below that I'm using to capture the key events. Note how appuifw.app.body is utilising a callback function to capture these events.
Code:
import e32, appuifw, datetime
canvas = None
text = ''
keymap = {}
firstTimeKeyPressed = True
def getFlightTime(sTime):
global firstTimeKeyPressed
global keyPressTime
global keyDelta
if firstTimeKeyPressed:
firstTimeKeyPressed = False
keyPressTime = sTime
else:
keyDelta = datetime.datetime.now() - keyPressTime
keyPressTime = datetime.datetime.now()
return keyDelta
def event_callback(event):
global text
pressTime = datetime.datetime.now()
flightTime = getFlightTime(pressTime)
if canvas is None:
return
eventType = event['type']
scancode = event['scancode']
if eventType == appuifw.EEventKeyDown:
keymap[scancode] = datetime.datetime.now()
text = 'KeyDown %d' % scancode
redraw()
elif eventType == appuifw.EEventKeyUp:
try:
delta = datetime.datetime.now() - keymap[scancode]
del keymap[scancode]
except KeyError:
delta = -1
releaseTime = datetime.datetime.now()
text = '\n%s\n%s\n%d\n%s\n%s' % (pressTime, flightTime, scancode - 48, delta, releaseTime)
print text
redraw()
def redraw_callback(bounds):
redraw()
def redraw():
if canvas is None:
return
canvas.clear()
canvas.text((10, 20), unicode(text))
canvas = appuifw.Canvas(redraw_callback = redraw_callback,
event_callback = event_callback)
appuifw.app.body = canvas
lock = e32.Ao_lock()
appuifw.app.exit_key_handler = lambda: lock.signal()
lock.wait()
|
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Online
Forum Nokia Champion
|
|
If detecting keypresses and not key up or key down events is enough you can use the keycapture module. Otherwise you might be able to use your own Keyboard class that detects events, like in this article. Haven't tested it though.
Last edited by bogdan.galiceanu : 2009-04-28 at 06:28.
|
|
bogdan.galiceanu: Thanks for your reply. Originally I implemented the Keyboard class but this has some problems whereby it made it difficult for me to add specific methods i required (like getting fligh times of keys and dwell times) as detailed in my previous example. Additionally, their method for checking is a key pressed (polling) is really inefficient as it's really heavy on power consumption. Regardless of this, the article which you linked me to exhibits the same problem whereby their Keyboard class is initiated using the
Code:
app.body = canvas = Canvas(event_callback=key.handle_event) |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| how to simulate the key press events in BREW?? | rajesshwari | Other Programming Discussion 关于其他编程技术的讨论 | 2 | 2009-02-06 15:34 |
| how to differentiate between call end key and Task list cancel events?? | mayudada | General Symbian C++ | 3 | 2007-11-01 15:05 |
| Web application freezes key events processing | ten0s | General Symbian C++ | 0 | 2007-04-03 18:22 |
| Key events while a dialog is open | ShabbirPatel | Symbian User Interface | 0 | 2006-05-23 17:35 |