Try cleaning the keyboard by following the instructions in this Apple article:
How to clean the keyboard of your MacBook or MacBook Pro - Apple Support
Make sure to keep the can of compressed air completely upright or you may damage the laptop with the cold wet propellant.
If you have a 2016-2019 model, then you likely have a model with the dreaded butterfly keyboard mechanism which has a known design & manufacturing defects. Apple has a free Keyboard repair program to address the issue, but it is only valid for up to four years after purchase....meaning most of the laptops no longer qualify.
Keyboard Service Program for MacBook, MacBook Air, and MacBook Pro - Apple Support
If your laptop does not qualify for the free Keyboard repair program, then check the condition of the battery. If it shows "Service Recommended", then you can have Apple replace the Battery for you for a much lower cost than having the keyboard replaced...just do not mention the key issues, or the tech may only offer the more expensive repair. The same exact part will be replaced since the battery is glued to the underside of the Palmrest & trackpad which is part of the Top Case Assembly.
FYI, here is the current list of the publicly acknowledged free repair programs for various Apple devices:
Apple Service Programs - Apple Support