Detecting Third button press

Your switches are not wired properly.

Most here recommend wiring your switches as S3 in the image below: