In my case, the problem was the cable connecting the touchpad to the motherboard. One of the wires in the cable was not conducting the electricity anymore. That crippled the communication between the motherboard and the touchpad. But because the keyboard is attached to the motherboard over the touchpad, the keyboard did not work as well. The only button that was still working was the power button. Likely because it does not communicate with the motherboard over the message bus (which was crippled) but over a distinct wire in the cable.
I ordered a new flex cable on the internet. But the cable I got was for an older version of MacBook Air (it looked the same, the size was the same, but it had fewer wires). Once I got the correct version of the cable, everything worked again.