Key switches provide the interface between the mechanical and the electrical portions of the piano.
The vast majority of commercial keyboards use rubber membrane key-switches. While these are one of the most inexpensive technologies to mass-produce since the switches for many keys are effectively stamped into one part, they have a limited lifetime, and are typically one of the first things to fail in commercial keyboards.
LED/Photodiode pairs are more reliable than rubber keyswitches, and are already seem to be the for retrofitting acoustic pianos with digital technology.
Magnetic switches (hall effect sensors). Hall effect sensors are four terminal devices. If put a current across the chip in one direction, an applied magnetic field will alter the trajectory of the moving electrons, resulting in a measurable voltage potential across the other two pins. While these can be as cheap as optical sensors, it is a lot harder to prevent magnetic interference between keys than it is to prevent optical interference.
The major drawback of capacitive switches is that they require a rather high voltage bus in order to have good noise immunity.