Fix error in the key scanning code