Key on shaft, then install pulley.
This is a square cut key, and I've had bad luck installing them key first, but it depends on how the slot was made.
1) The usual method of cutting the slot is with a horizontal mill with a large cutter. Done this way, the slot stays square for at least the width of the pulley, but then curves up towards the surface like this:
In this style, if you insert the key first, friction with the pulley will drag the key further onto the shaft, and if the key gets driven onto the shallow region, you will do bad things as you drive the pulley on.
For this style of key slot, what I do depends on how loose the key is in the pulley slot. I want to start the key partially in the shaft slot and slide the pulley over it, ending with the key at least halfway in when the pulley is positioned, and finish by driving the key all the way home, usually with a wooden dowel and hammer. If the pulley is tight, I may have to start with only 1/8" of key in the slot and end with a brass drivt, but if it's loose, maybe I'll only leave 1/8" sticking out and just push it in with my finger (this is NOT ideal, but is acceptable for lower power motors).
2) The other way of cutting a square key slot is with a vertical end mill. On these, the key slot ends at full depth with a rounded end. This method is usually reserved for Pratt & Whitney keys where the slot is entirely on the shaft and doesn't exit at the end, but not always. Anyway, with a Pratt & Whitney key (or a woodruff key), where the key will stay in the correct position as the pulley is inserted, your method works well.