First, try an SMC reset:
Reset the SMC of your Mac - Apple Support
In notebook Macs, unexpected behavior of either the trackpad or keyboard can be caused by a swelling battery. Some things to check that don't require opening the computer:
—Feel the joint between the trackpad and upper deck. It should not be higher on one side compared to the other, and the trackpad should show no bulging
—Carefully examine the line where the chassis meets the bottom plate. The joint should be uniform. Missing screws can means the battery has been putting pressure on the bottom plate.
—Place the computer on a known level surface. Granite and solid-surface ceramic counter tops are great. See if the computer rocks when you apply ligh tpressure. Rocking indicates one of the rubber feet is not touching down and can herald a swollen battery.
If you see any hint of these, get the computer to Apple or an Apple Authorized Service Provider as soon as possible for evaluation. Batteries can swell quite fast and can destroy a computer in days if not addressed.