It could be either the cable/connector that is connecting the keyboard to the motherboard is either bad, or loose or the actual keyboard is bad. The only way to find that out is to open up the laptop and check the keyboard connection to the motherboard. Taking apart laptops are pretty tricky, so only do that if you know what you're doing, or take it to a professional.
Also, you can try to plug in a USB keyboard and go to the BIOS and make sure you don't have anything that says disabled that has to do with keyboard. With the USB keyboard plugged in, turn on the computer and press 'F8' and boot into safe mode. When it successfully boots, unplug the USB keyboard and test to see if the keyboard on your laptop is working. If it does work, it's some sort of software running on your laptop that is making your keyboard work properly.