Improve handling of keyboard shortcuts