Better algorithm for determining the new keyboard frame