I usually use grease to hold a key in place for assembly in a slip fit keyway. In extreme cases, I have been known to drill through the key & tap a thread in the bottom of the keyway so that I can use a small machine screw to hold the key in place. The hole will either need to be countersunk or counter bored, depending on what type of screw you want to use. I usually also file a small ramp in the front edge of the key to help it slide into the broached female keyway above the shaft, rather than hit against it & push out of the keyway in the shaft.
If I am installing a pres fit key in a shaft & I expect to have difficulty removing it in the future, I will again pull out the tap. In this case, I will tap a thread into the key so that I can use a jack screw to remove it in the future.
If I have a tight key with no jack screw thread in it & no suitable tap/screw available to remove it, I have been known to drill an 1/8" hole in the key, fill it with grease, put a tight fitting 1/8" pin punch on top of the grease & hit it with a hammer. The hydraulic pressure of the grease will usually break the key free & budge it out of place by a few thousandths. I then try to get a grip on the key with pliars & remove it. If that doesn't work, I go to vice grips, which usually damage the key & require subsequent replacement of the key or dressing of the key with a file, if you are going to use the key again. If that doesn't work, then I have been known to reach for a 1/4" cold chisel & a hammer. I chisel a groove into the edge of the key & then change the angle to hammer the key out of place. At this point, you are abandoning the key & planning to replace it.