×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Unhappy How to handle key presses?

    Hi,

    I have an extremely simple pys60 script under development. It's about as simple as you make: show a color. Just one color. Full screen.

    So far I've rewritten the #%#¤ script 5 times, because keyboard handling is pretty darn hard in pys60.

    The first version used a busy loop, which mostly worked, but I just don't like busy loops. The keyboard handling turned into 100 LOC monster, which just got out of control for this kind of app. Too many special cases with different states of script: state machine with as many as 3 states !!! Ok, counting "starting" and "exiting" that's 5 states. Got some crashes, when pressing keys at the wrong time. Crashes are not allowed. Ever. No excuses.

    Current version uses binding keypresses to functions, which then are supposed to take care of some things. The problem is that I get 3 events per one physical finger press... I can feel special cases creeping in again, this time into about 15 different places.

    Latest plan number 6 is to combine both key event binding AND one central messy key handling function - but I'm getting tired of having such basic problems for such basic app. I mean, I just want to show one color

    Question:

    Any recommendations about a reusable, reliable and simple way to handle key events? Wiki has one code sample, which has got one review: one point out of five. That's not a good recommendation for a sample, at least not to me. Also I tried that once already.

    Yep, I got the "mobile Python" book and I tried their code in version 3, I guess. Not much improvement over default Nokia sample. Messy.

    Cheers,

    --jouni who wants one event for one key press UNLESS he especially requests to get more events

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    125

    Re: How to handle key presses?

    Quote Originally Posted by JOM View Post
    Any recommendations about a reusable, reliable and simple way to handle key events?
    I'm assuming it's a Canvas-based script. The ball.py example which comes with the PythonScriptShell package might be a good example. You don't need to sit in a loop after the script has run - just wait on an Ao_lock, and have one of the keys signal the lock to exit the program.

    The reason you're getting 3 events is because every time a key is pressed, you get an EEventKeyDown and (perhaps) an EEventKey, then an EEventKeyUp when you release the key. You need to check the event type, and handle it appropriately.

    Post some of the source code if you want more help.

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: How to handle key presses?

    Yep, Canvas-based script. I'll check ball.py again, thanx for reminder!

    In the meanwhile I put together a version where all recognized keys are binded and all key handlers call same "status" function before doing anything. That function gives or denies a permission to continue the normal operation. Seems to be more stable than any other previous experiment, so I hope to get it released during this trip == two more nights in a hotel.

    Thanx,

    --jouni

Similar Threads

  1. Handling long and short key presses for ABC key
    By jessyjane in forum Symbian User Interface
    Replies: 4
    Last Post: 2008-09-09, 08:47
  2. Simulating key presses in S60:
    By saurabh2801 in forum Symbian C++
    Replies: 18
    Last Post: 2007-07-18, 12:27
  3. Handling key presses within different views
    By NigelT in forum Symbian C++
    Replies: 0
    Last Post: 2006-12-21, 18:23
  4. Synthesize key presses
    By newnb in forum Symbian C++
    Replies: 4
    Last Post: 2006-11-01, 06:13
  5. Handling simultaneous key presses in game
    By e_morko in forum Symbian C++
    Replies: 2
    Last Post: 2005-01-20, 15:03

Posting Permissions

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