This is a very simple example of how to write a composing input method.
It will convert a sequence of four hex digits to one Unicode character.
Shift+space toggles the input method on/off, and the return key accepts
the composed text. Backspace removes the last composed character.

A proper input method would implement cursor movement and a more
sophisticated state machine, but that would make the code more
complex and harder to understand.