relays to keyboards
If you use electronic circuits to drive switches, the drive circuits will normally have a common ground. In this case you can use relays or Opto-couplers to make the isolation between drive circuit and keyboard.
Connection of a relay is pretty straight forward: The driver circuit connects to the relay coil which does not have any polarity. The only thing to take care or is that the driver circuit applies voltage across the coil which matches the relay coil spec. This coil voltage is normally printed on the relay housing. The relay contacts connect to the keyboard and dont have polarity either. In case the relay has Make/Break contacts, make sure you connect the Normally Open contacts to the keyboard.
Take note that when you drive the relay coil directly with a switch (either mechanical or electrical) you get a voltage spike over the coil when switching OFF the coil current. To suppress this spike, add a diode over the coil as shown below.
Relay connection and spike protection
For various types of relay and specs, check: http://www.oeg.com.cn/grlist.htm