I would inspect the keyboard cable and the connection to the logic board.
Disconnect the battery and carefully slide out the ribbon cable from the socket use cotton swab (Q-Tip) with some reagent grade Isopropyl alcohol to wipe the contact surface, if it looks damaged you may need a new keyboard.
+
+
Refer to Step 24 & 25 here: [https://www.ifixit.com/Guide/MacBook+Pro+15-Inch+Retina+Display+Mid+2012+Logic+Board+Replacement/9725]
I would inspect the keyboard cable and the connection to the logic board.
Disconnect the battery and carefully slide out the ribbon cable from the socket use cotton swab (Q-Tip) with some reagent grade Isopropyl alcohol to wipe the contact surface, if it looks damaged you may need a new keyboard.