extract & improve app.keys and app.grab_focus

(see commit messages)