Friday, July 08, 2022

Micropython - Keyboard library with chording, layers, etc.

 I'm working on a project to build an interacive terminal using micropython, and a component of that is checking for button presses and translating them to keys to be used to control the terminal or however that works.  

I've made a couple of attempts at keyboard firmwares in the past and changed strategies this time from key-focused to event-focused - events start when a key is pressed and terminate after either a hold timer or key that is part of the event is released.  

Based on the numbers of keys in the event, their functions, and hold duration, we can figure out the correct keyboard key to be returned.  

Examples to consider:

  • Chords can map combinations of keys to letters, numbers, or symbols,
  • A single key, if held for some duration, can trigger a layer shift and then subsequent keys or combinations of keys can result in letters, numbers, etc from that layer. 
  • Short taps result in a number, letter, etc. 
Anyway, this might be a helpful template for anyone trying to do something similar:

https://github.com/a8ksh4/MicroNote/blob/main/keeb.py

No comments: