| Reply | « Previous Thread | Next Thread » |
|
Hey,
I want to write a small application to convert key presses to characters like what happens when you're writing an SMS. For this, i wrote a quick script that converts an array of numbers back to characters using a keyMap. The following is the code: Code:
import sys
keyMap = {
2: ['a', 'b', 'c'],
3: ['d', 'e', 'f'],
4: ['g', 'h', 'i'],
5: ['j', 'k', 'l'],
6: ['m', 'n', 'o'],
7: ['p', 'q', 'r', 's'],
8: ['t', 'u', 'v'],
9: ['w', 'x', 'y', 'z']
}
# h e y
#keysPressed = [4, 4, 3, 3, 9, 9, 9]
# h e l l o
keysPressed = [4, 4, 3, 3, 5, 5, 5, 5, 5, 5, 6, 6, 6]
prevkey = ''
counter = 0
counter2 = 0;
for key in keysPressed:
if (prevkey == key):
counter += 1
else:
if (prevkey != ''):
sys.stdout.write(keyMap[prevkey][counter - 3])
counter = 0
prevkey = key
print keyMap[prevkey][counter]
Thanks, A |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| I would like to convert numbers from binary system to decimal | sirmic | General Symbian C++ | 4 | 2008-03-04 12:15 |