Added key detection and handling.