×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    7

    SMS Composer + Key Events

    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

  2. #2
    Regular Contributor
    Join Date
    Jan 2009
    Location
    India
    Posts
    138

    Re: SMS Composer + Key Events

    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
    Sr. Software Engineer
    http://windows-mobile-dev.blogspot.com

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    7

    Re: SMS Composer + Key Events

    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?

  4. #4
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: SMS Composer + Key Events

    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 05:28.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    7

    Re: SMS Composer + Key Events

    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?

Similar Threads

  1. how to simulate the key press events in BREW??
    By rajesshwari in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 2
    Last Post: 2009-02-06, 14:34
  2. Replies: 3
    Last Post: 2007-11-01, 14:05
  3. Replies: 0
    Last Post: 2007-04-03, 17:22
  4. Key events while a dialog is open
    By ShabbirPatel in forum Symbian User Interface
    Replies: 0
    Last Post: 2006-05-23, 16:35

Posting Permissions

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