Crates.io | keytokey |
lib.rs | keytokey |
version | 0.5.0 |
source | src |
created_at | 2019-08-05 22:01:01.798058 |
updated_at | 2024-09-23 18:25:55.291774 |
description | A keyboard firmware library turning event streams of key presses into reports for USB |
homepage | |
repository | https://github.com/TyberiusPrime/KeyToKey |
max_upload_size | |
id | 154388 |
size | 209,425 |
KeyToKey (K2K) is a Rust libary for building keyboard firmwares.
Basically, a keyboard firmware a) reads key-presses, b) translates them c) and outputs the results to a computer.
KeyToKey's role is in b - it takes a stream of events, such as key presses, releases and timeouts, and translates them using a series of handler trait objects into reports that can easily be converted to the format USB expects.
This is inspired by the QMK mechanical keyboard firmware, which probably is the most feature complete keyboard firmware to date. Alas it's C, and an amazing ball of ifdefs that usually needs more flash than the micros it's targeting offer.
The trait object oriented approach chosen here allows composition of arbitrarily complex keyboard layouts - and unit testing them without hardware.
To get started, maybe check out the reference firmware.
KeyToKey operates on key codes that are u32 representing unicode key points. (The USB keycodes are nested in the first 'private area' of the unicode code set, and the rest of the private area is free to be used by the keyboard implementor.)
A basic keyboard uses two handlers - a handlers::UnicodeKeyboard, which sends the OS-specific magic 'enter-an-arbitrary-unicode-keypoint' for any key code outside of the private areas, and a handlers::USBKeyboard which handles all the usual 'tell the computer which buttons are pressed' functionality including modifiers.
USBKeyboard does not limit the number of simultanious keys, but the downstream translation into USB might restrict to the usual 6 key rollover.
Basic features
Advanced Features working
t e h
-> the
which don't intercept the keycodes, but then send a set of backspace presses, and then your action)Advanced features planned
Leader sequences (e.g. hit leader h e a r t
to enter a heart emoji, or an arbitrary string)
TapDance (count the number of taps on a key, pass the final count to a callback)
AutoShift - Short tap: lower case, longer tap: uppercase. Removes key repeat though.
send keys later (e.g. for a macro that sends a key after a delay)
K2K strives to seperate the triggers (when does something happen) from the actual actions. Currently actions may be arbitrary (USB) KeyCodes being registered, &str being send or callbacks (implemented via traits)
Other rust firmwares / keyboard libraries