Keyboards wear out. They fail. It is actually one of the more common repair issues.
99% of all keyboard problems are caused by hardware failure.
If yours is a desktop, replacing a keyboard is a trip to the store to buy a new one. You can buy them form $10 to $100. Check carefully, many times there is not much difference.
If yours is a laptop, replacing can become a significant technical challenge that is beyond most people and requires a competent technician. Make certain that the keyboard installed is in fact the exact model. There are many that look a lot alike, that will cause you problems. Cost likely approaching $100. An alternative is to buy an external one, just like that used on a desktop PC.
You can diagnose a laptop by using a wired known-good USB keyboard to test.
There are some laptop models for which a keyboard change is relatively simple. Check Youtube for your specific model. I mean your specific model. The simple ones are removed by pressing down on a tiny tab at the top of the keyboard. There are likely 4 or 5 of those tabs, so you have to kind of release one and hold it up while releasing more. When you get it right it will just pop off. It is connected by a ribbon cable to the computer.
Be very careful to get the right replacement. Many are similar but if you do not get the right on, you are not going to be happy,
The good news is that these are relatively inexpensive.