better keyboard detection