There are a few different ways that legends are done for keycaps. Below are some of those most common you will see around the enthusiast community.
A method of injection molding where the legend and the outer base of the cap are two separate parts that are molded together. The legend will never fade, as it goes all the way through the cap. This is usually done with ABS plastic.
Dye-Sublimation (Dye Sub)
A method where the legend is a dye that is embedded into the surface of a solid cap composed of one part. A simple way to describe this method is to think of the legend as being tattooed into the cap. The legend will eventually fade over time with use as the cap is worn but will hold up pretty well as the legend is embedded into the surface of the cap. This is usually done with PBT plastic.
Reverse Dye-Sublimation (Reverse Dye Sub)
The same dying method as regular dye sub above, but instead of the legend being dyed onto the cap, everything except the legend is dyed. This is used when the legend is a lighter color than the base color, because you cannot dye a darker color lighter than it is. So you start with a lighter cap and dye the entire cap and leave the legend un-dyed.
A method of digital printing utilizing ultraviolet (UV) light to dry or cure the ink. This is most commonly used for legends that are a third color on a double shot cap. The legend will fade faster than dye-sub as the cap as the legend is on the surface of the cap. However, some companies have very high-quality UV printing that has proven to last years.