Do you have another keyboard you can test with? Maybe get one from a friend for an hour or so?
If the problem goes away with another keyboard you may need a new one.
I would start with making sure the keyboard is plugged all the way in and isn't loose.