Refactor keyboard support in to a switch/case structure for #426