refactored keyboard behavior so it only does things once