These keycaps lock into a tiny bit of plastic known as the keycap retainer.
These are usually small, plastic circles or squares which lock the keycap into place.
If there’s a bit of plastic with your keycap, it’s likely the retainer.

orcearo / Getty Images
Gently place your retainer back onto the spot where it came off.
With the key retainer in place, position your keycap on top of the retainer.
Check the retainer and the underside of the keycap to find out the correct orientation.

The Spruce / Ana Cadena
Press down lightly and listen for a click; this signals the keycap has locked into the retainer.
If it seems misaligned, press down gently on the key until it’s positioned correctly.
Firstly, routine cleaning is essential.

Jacob Lund / Shutterstock
Keycaps can come off after residue builds up underneath them and works to separate the keycap from its retainer.
Giving your keyboard a regular wipe-down is a great way to keep your keyboard clean and residue-free.
Check with the manufacturer to learn what is recommended (and learn what can harm the keyboard).

© Tonic Photo Studios / Photographer’s Choice / Getty
The Spruce / Ana Cadena
Second, be aware of how hard you’re pressing down on your keys!
Jacob Lund / Shutterstock
Lastly, be careful of spills near your keyboard.
Even the best maintenance can sometimes still not be enough.
Sometimes the keys just can’t be fixed.
In those cases, your options are to replace the keyboard or replace the entire laptop.
FAQ
First, unplug your laptop and remove the battery if necessary.
Alternatively, you might quickly lock your system usingWin+LorCTRL+ALT+Deleteto prevent accidental typing.
MacBook users can temporarily kill the keyboard by closing the lid or by using the shortcutControl+Shift+Power.
If your laptopkeyboard isn’t working, there are some troubleshooting steps you’re free to try.
Give it a good cleaning, try restarting the system, or replace any broken keys.