This is something I needed to make an interactive micropython terminal without using the serial connection to interact with it. E.g. a separate library handles keyborad scanning using the pi pico pins and when a keypress is registered, a callback function is used to pass the dupterm instance. Since I want to use fbconsole to display the console on a screen, it made sense to add the needed bits to the fbconsole library to support passing in the keystrokes:
In our display module:
And for a callback function, we can use something like this:
To pass in single or multiple characters, you can use the inject method. You'll see them appear in the terminal when the function is called:
Within fbconsole.py, we add a couple imports, constants, and define self._data in __init__:
And methods in the class:
And finally modify the readinto method.
Finally, in addition to regular numbers, letters, and symbols, you'll need a few ascii codes to pass in enter, backspace, etc as well as ctrl+key cobmos:
I'll do a followup article with more info on ctrl and other special characters. We should be able to pass in arrows to move the cursor, etc.
Finally, this article will be updated with a link to the complete code soon.