Added centralized key handler for smoother input response