View Single Post
ossipena's Avatar
Posts: 3,159 | Thanked: 2,023 times | Joined on Feb 2008 @ Finland
#25
Originally Posted by aspidites View Post
I don't see a screenshot... I see it now.

Anyways, as for the "aaaaaa" what about keeping a global variable (or class attribute) that keeps track of the number of sequential presses?

Something like:
Code:
sequential_presses  = 0
last_key_pressed = None

on_key_press(key):
  if key == last_key_pressed:
    seuqential_presses +=1
  else:
    sequential_presses = 1
    last_key_pressed = key

  if sequential_presses == 1:
    ..
  elif sequential_presses == 2:
    ..
Of course, using something like this would be more pythonic than the if/elif clauses. I don't know what toolkit you're using, so it's hard to give concrete examples. Also, it might be worth using ord() or char() instead of manually having to figure out which character needs to be displayed.

BTW, space is usually the 0 key, isn't it? Might help if each key had the letters it can input under them in a smaller font. Looking good so far though.

edit:
Just another idea:
Code:
letters = {}
letters[2] = [_, 'a', 'b', 'c']
letters[3] = [_, 'd', 'e', 'f']

print letters[key][sequential_presses]
The names are verbose just to convey my ideas. Also, the _ is used so that you don't have to do something like "sequential_presses - 1" when doing index referencing.
thanks a lot, this might do the trick. shame that I am really busy @work so I must wake early and stop for today.
__________________
Want to know something?
K.I.S.S. approach:
wiki category:beginners. Browse it through and you'll be much wiser!
If the link doesn't help, just use
Google Custom Search