Improved calculating keyboard size