Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neradoc/circuitpython_keyboard_layouts
A repository of keyboard layouts for Circuitpython, for HID keyboards over USB or BLE.
https://github.com/neradoc/circuitpython_keyboard_layouts
circuitpython keyboard keyboard-layout
Last synced: 2 months ago
JSON representation
A repository of keyboard layouts for Circuitpython, for HID keyboards over USB or BLE.
- Host: GitHub
- URL: https://github.com/neradoc/circuitpython_keyboard_layouts
- Owner: Neradoc
- License: mit
- Created: 2021-07-09T23:07:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-21T23:08:07.000Z (about 1 year ago)
- Last Synced: 2024-10-09T22:41:42.793Z (2 months ago)
- Topics: circuitpython, keyboard, keyboard-layout
- Language: Python
- Homepage:
- Size: 2.55 MB
- Stars: 91
- Watchers: 5
- Forks: 18
- Open Issues: 9
-
Metadata Files:
- Readme: README-DEV.md
- License: LICENSE
Awesome Lists containing this project
README
### KeyboardLayoutBase class
- ASCII_TO_KEYCODE is a bytes string with the keycode for each low-ascii character at the ascii value place. The keycode for "u" is at: `ASCII_TO_KEYCODE[ord("u")]`. Since the keycode value is below 0x80, the high bit is used to encode if the shift key is needed.
- `NEED_ALTGR` lists characters that require the altgr key in addition.
- `HIGHER_ASCII` is a dictionary that associates the `ord()` int value of high ascii and utf8 characters of one or more bytes to the keycode.
- `COMBINED_KEYS` is a table (dictionary) of characters like `Ñ` that can be accessed by typing first a dead key (like `~`) followed by a regular key (like `N`) - on a Windows French keyboard for example.
- Indexes are `ord()` int values of each character.
- The value is an int encoding 2 bytes.
- The upper byte is the keycode of the first key, including the shift bit.
- The lower byte is the ascii code of the second key (a-z, A-Z or space).
- The lower byte's high bit also encodes whether or not the first key needs altgr, so as not to pack NEEDS_ALTGR with a bunch of characters.With the `Ñ` example:
- `~` is altgr + `é`, `é` is keycode 0x1F
- `N` is ascii code 0x4E, with the altgr bit becomes 0xCE
- `Ñ` is therefore `0xD1: 0x1FCE,`
- When typing, "N" is looked up: `ASCII_TO_KEYCODE[0x4E] == 0x91` (shift+0x11)
- So `write("Ñ")` sends the keycodes: `(0xE6, 0x1F)` (altgr+é) then `(0xE1, 0x11)` (shift+n)Using int values to index the dictionaries, and as values for the `COMBINED_KEYS` table reduces the memory size compared to strings and bytestrings.
### Layouts and KeyboardLayout classes
Every layout class is called KeyboardLayout, to make changing layout easier without having a different class name in every file, and have to guess or lookup the class name (is it CamelCase of the module name ? Is it US or Us ?). For compatibility, I added `KeyboardLayout = KeyboardLayoutUS` in the US keyboard layout. Importing multiple layouts is possible by using the full `module.KeyboardLayout` name, or `import KeyboardLayout as ...`