Hi,
Since you've replaced the keyboard already with a new one that means it should have resolved the issue already. Do try to uninstall/reinstall the keyboard driver from Device Manager as well that may help in solving the issue. Have you also tried reinstalling Windows with your laptop? If you've already tried all these troubleshooting steps that means the problem lies inside the motherboard where you connect the ribbon cable. Try cleaning it first then reconnect the ribbon cable of the keyboard and see if it would solve the problem or not.