keyboard or logic board problem?
If the only thing that's broken is the keyboard/typing, your logic board is most likely fine.

The logic board (motherboard) will cause lots of problems if it's broken. The fact that your computer is working (mostly) normally means that the logic board is probably fine.
If you want to know for sure, you can run Apple Hardware Test to find out.

It is entirely possible that your keyboard isn't working, but before you buy a new one you may as well look to make sure it isn't a software problem.
Can you detect any pattern in when you have this problem? Are some apps worse than others? If so, it's likely that this is a software problem instead of a hardware problem.

To troubleshoot a software problem, I recommend that you do a safe boot and try typing. If the problem doesn't occur, you know that it is being caused by something related to your account. Try quitting apps and making sure that no startup items are being troublesome.