Refactor keymap code to avoid duplication ("Daniel P. Berrange")