A lot of it depends on whether the switch is stand-alone (dedicated input to the microcontroller), or is part of a switch matrix that is scanned. A stand alone switch has some bias voltage that you can measure and then control with a transistor or opto isolator once you know the polarity. A switch in a matrix can't be controlled that way because there is no fixed voltage reference for the transistor. Hence, a relay can work because it is indifferent to polarity.