Fixed keyboard and mouse loss

Replaced check with multiple checks.