Laptop keyboard randomly not registering
I would reset the SMC on your Mac. Of course you would need certain keys to work for it to be successful. 

How to reset the System Management Controller (SMC) on your Mac

https://support.apple.com/en-us/HT201295

If that doesnt help, my next suggestion is to boot the Mac into Safe Mode and test the keyboard. If the keyboard works then you may need to just reinstall MacOS. If it doesnt then you may need to call Apple Support and set up an appointment for your local Apple Store if you have one.

Use safe mode to isolate issues with your Mac -
 https://support.apple.com/en-us/HT201262

Here is an interesting article by MacWorld

https://www.macworld.co.uk/how-to/mac/how-fix-mac-keyboard-3598931/