The C64 keyboard matrix is controlled by one of the two CIAs, namely, CIA1 (U1 in most schematics). If you have both CIAs socketed, try swapping them. If CIA1 was damaged, after swapping them, the damaged CIA, now in CIA2, may affect operation of other parts of the C64 (depending on what is damaged). If the damage is only present in the GPIOs, then the C64 may boot with a full working keyboard, but with issues in the IEC port. It might even prevent the C64 to boot properly.
On the other hand, if you have another socketed full working C64, you may borrow one of its CIAs, put it in the place of CIA1 in the affected computer and put the damaged CIA in the donor computer to check if the issue is now present in the donor computer.
If it happens that the CIA is not damaged, then the last thing to check is for bad soldering at the keyboard connector (resoldering it may help). Try reseating CIA1 in its socket, if socketed (take off CIA1, inspect and clean, if needed, both the socket and the pins of the chip, and put it again)