Skip to content

Commit 5b4f32a

Browse files
dupontguGuy Dupont
andauthored
add support for layouts where keys have no letters (#4)
* add support for layouts where keys have no letters * update readme with instructions for custom layout Co-authored-by: Guy Dupont <[email protected]>
1 parent 8c6c3a9 commit 5b4f32a

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

fw/README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,41 @@ tested natively on desktop. *For key press detection on Mac, you'll need to give
2222
1. Run `python3 bundle.py` from this directory. This will create a `bundle` directory, which will copy all required files into folders to be loaded onto each board.
2323
2. Find the directory with your board's name in the `bundle` directory. Copy all files/subdirectories onto your CircuitPython device.
2424
3. If your board requires third-party libraries to run this code (most do), you may have to manually copy them. Each board's `bundle` directory will contain a README listing all of the required dependencies. Official CircuitPython libraries available [here](https://circuitpython.org/libraries). As of May 2021, I have been using Bundle version 6.x.
25-
4. If you're using one of the desktop versions, execute `python3 code.py` from the `bundle/[macos/win32]` directory. You'll have to `pip3 install pynput` as well.
25+
4. If you're using one of the desktop versions, execute `python3 code.py` from the `bundle/[macos/win32]` directory. You'll have to `pip3 install pynput` as well.
26+
27+
## Customizing the keypad layout
28+
29+
You can customize which letters get attached to each key by changing the `keypad_dict` dictionary in `code.py`. The default is:
30+
```python
31+
keypad_dict = {
32+
'1' : ['1'],
33+
'2' : ['a', 'b', 'c'],
34+
'3' : ['d', 'e', 'f'],
35+
'4' : ['g', 'h', 'i'],
36+
'5' : ['j', 'k', 'l'],
37+
'6' : ['m', 'n', 'o'],
38+
'7' : ['p', 'q', 'r', 's'],
39+
'8' : ['t', 'u', 'v'],
40+
'9' : ['w', 'x', 'y', 'z'],
41+
'0' : [' ', '0', '\n'],
42+
'#' : ['.', ',', '?', '!']
43+
}
44+
```
45+
But as [Ben Torvaney discovered](https://torvaney.github.io/projects/t9-optimised.html), you can optimize your typing even further by using something like:
46+
```python
47+
keypad_dict = {
48+
'1' : ['1'],
49+
'2' : ['a', 'm', 'r'],
50+
'3' : ['c', 'd', 'f', 'p', 'u'],
51+
'4' : ['h', 'n', 'q', 't'],
52+
'5' : ['i', 'l', 'w', 'y'],
53+
'6' : ['b', 'e', 'g', 'v', 'x'],
54+
'7' : ['j', 'k', 'o', 's', 'z'],
55+
'8' : ['8'],
56+
'9' : ['9'],
57+
'0' : [' ', '0', '\n'],
58+
'#' : ['.', ',', '?', '!']
59+
}
60+
```
61+
62+
**Note that the keypad will not run unless all characters are accounted for!**

fw/core/code.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ def poll_keys():
354354
# ignore any other keys we don't understand
355355
elif c < '2' or c > '9':
356356
break
357+
# emit for any number keys that don't have letters (if user has customized layout)
358+
elif ord(keypad_dict[c][0]) < ord('a'):
359+
emit_raw_text(keypad_dict[c][0])
360+
break
357361
else:
358362
# search the dictionary!
359363
result = get_words(fp, c, last_result)

0 commit comments

Comments
 (0)