Good point. I think a fellow developer on the PDF reader project implemented something like this there:
https://github.com/hwhw/kindlepdfvie...aster/keys.lua line 181 onwards.
It's probably overkill to ask for the setting upon each key press, so this could be done once, e.g. by putting it on global level (i.e. not in a function).
That's the nice thing when you use a programming language as configuration language :-)
Edit: Ah, dave beat me to it. That's often the case lately :-P (it's a good thing...). Yep, my preference for Lua had its effect on both projects. It's just so damn easy to integrate into C code and really helps people to realize complex szenarios.