added locking around the keyboard echoing logic