I once worked at an office where the locked bathroom door did not necessarily mean that it was occupied. The lock was wonky, and although it was easy to lock, it required an extra step to unlock it. And when unlocking, if you failed to jiggle the lock, it would remain locked (and it swung shut). So at this office, the key was on a hook next to the door.
One employee got in the habit of grabbing the key, giving a perfunctory jiggle as she was inserting the key, and walking in on you (well, actually me) in mid-use. Although, to be honest, even if she had knocked, she always proceeded on the assumption that the door was locked in error, so maybe knocking with her would not have worked either.