Keys and clicks can be handled by anything that registers for an input handler, by using the API: ContextPtr:SetInputHandler. Most times, work associated with the in-game action bound to a key is happens in the 'up' phase. Down is the act of pressing a key or mouse button down, up is the act of releasing that key or button. Keys and mouse clicks in Civ 6 are split into two phases: 'down' and 'up'. Reviewing this information below is useful for understanding the example at the bottom of this article.
This page provides details on what CQUI (and other mods) do in order to add additional key handlers to actions in the game, beyond those offered in-box from Firaxis.