You Are Here:

Community: Developer Discussion Boards

#1 Old SMS Composer + Key Events - 2009-04-27, 04:02

Join Date: Jan 2009
Posts: 7
aneville
Offline
Registered User
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
and my SMS composer application sets the following:

Code:
appuifw.app.body = appuifw.Text()
How can I go about integrating this so that I have a appuifw.Text() body that allows entering text while capturing the events at the same time?

Many Thanks,

A
Reply With Quote

#2 Old Re: SMS Composer + Key Events - 2009-04-27, 20:59

Join Date: Jan 2009
Posts: 64
Location: India
Send a message via AIM to pavan.pareta Send a message via MSN to pavan.pareta Send a message via Yahoo to pavan.pareta Send a message via Skype™ to pavan.pareta
pavan.pareta's Avatar
pavan.pareta
Offline
Regular Contributor
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
Reply With Quote

#3 Old Re: SMS Composer + Key Events - 2009-04-27, 23:07

Join Date: Jan 2009
Posts: 7
aneville
Offline
Registered User
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()
However, I want to make this application look like an SMS composer by using appuifw.app.body = appuifw.Text(), but this overwrites the callback function. Is there any way to achieve this or do i need to take a new approach?
Reply With Quote

#4 Old Re: SMS Composer + Key Events - 2009-04-28, 05:42

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
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.
Reply With Quote

#5 Old Re: SMS Composer + Key Events - 2009-04-28, 18:57

Join Date: Jan 2009
Posts: 7
aneville
Offline
Registered User
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)
This will stops me from actually entering text into a Text() body. Surely there must be a way to do this?
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ