Good keyboards are so cheap that spending much time troubleshooting or repairing them is counterproductive. Membrane keyboards are irreparable in practical terms. Mechanical and capacitive keyboards can be repaired, but with parts expensive and difficult to find and technicians charging $50+ per hour, it's cheaper just to buy a new one. The same goes for repairing a keyboard yourself, unless your time is worth nothing an hour.
If a keyboard stops working or behaves strangely, check to make sure the cables are connected properly. If everything appears to be correct, it's worth doing a simple swap to verify whether the problem is the keyboard or the PC. If a known-good keyboard also fails to work, the problem is most likely caused by a defective keyboard interface on the motherboard, for which the only realistic solutions are to substitute a USB keyboard or replace the motherboard. If the known-good keyboard works, replace the defective keyboard.