CBA provides functionality for Keyhandlers (keyUp and keyDown), scripted or read from config.
next to a lower level API to displayHandlers.
The displayhandler API will make sure the keyhandlers are re-attached after save/close game/start game/load,
while they keyhandlers on top of that provide a solid API and fast performance (array index).
If you would like to add configurable keybindings to your mod that users can change via an in-game menu, check the Keybinding system.