I was wondering the same, so many items seem to require a mill in addition to a lathe.
Can I mount a mill table vertical on the lathe and accomplish the same thing?
There's a reason most of us own a lathe and a mill. I ran into the same problem. You can do a milling attachment on the lathe, and get an adapter to use milling cutters in the lathe headstock. I've always read not to try holding end mills in the chuck. You can use end mill holders or collet chucks though. Milling attachments have issues with rigidity, so wind up making poor substitutes, but it can be done and works fine if you keep within the limitations. I bought one shortly before I found a mill, so if you want one let me know and I'll make you a deal.
So, as I see it there are 2 issues here to make a square ended shaft in a lathe, starting from round stock. Without more "fancy" tooling..
Indexing the sides
Cutting flats
There are only 4 sides for most chuck keys I've seen, so you can index using the 4 jaws on a 4 jaw chuck against the ways with a square. For cutting, you could use a toolpost mounted grinder. Maybe something like a dremmel tool with a cutoff wheel? You would need some way to prevent the chuck from rotating while cutting/grinding.
You can also come up with some way to hold the stock in the toolpost and the cutter in the headstock. Perhaps an endmill holder and use a boring bar holder for a QCTP to hold the round stock. Cut one flat and index against it with a square like above, use the set screws to hold it. Probably need light cuts.
You would want to find the size of the required square and calculate the size to cut so it fits the chuck. So you can use a micrometer to measure against the round to determine proper depth.
If I were to make one today, I would use a square collet block in the mill. But it's an interesting thought process.