A shaft collar on each side if possible... That keeps the key captive inbetween and locked to the drum/sprocket ect...
Another method is using pipe clamps either to hold onto the key itself( so the length of whatever hub, plus the width of the clamp)... Or clamps outside the hub instead of the collars.
On my bikes I have used all these methods as I had walked out keys 2 times, both I was just lucky to stop...
One thing you can do is not to weld it on, but to put a little bead of weld down in the keyway, on either side of the key. It will act as a physical stop for the key, while still allowing you to loosen the sprocket and slide it over to remove the key.
After two incendents involving brakes and keys(or lack there of...) I check them all in a pre trip before and after riding... Just to be sure....
My old work boots have a good flat spot on it from flintstoning it trying to stop...
Another thing I've seen done is the keyway filled with JB weld on either side of the key, then sanded flush. Totally removeable with a chisel down the road if you need to reposition the brake.
Hmm.. grub screws on the hub (whatever hub it is.. wheel, sprocket or -in your case- brake)
small drilled dimple on the key for the screw to locate into.
Since most hubs I know already have a grubscrew... all you need is to make a small dimple into the key most of the time
Unfortunately none of my hubs have grub screws. (I wish they did) Instead I've opted for anickode's J-B Weld method as I don't have a welder on hand or any welding experience/knowledge.
The only thing I don't like with the glue, is that it needs to be contained to the area of the key(and really just the end in the keyway, or it'll be a real pain if it gets on the shaft between the hub...
It's hard to get off metal and especially if things will need to be maintained and/replaced...
I, like the SS pipe clamps, no fuss no muss...
I used some J-B Weld SteelStik to form stops in the keyway to keep the keys from backing out. I'll see how well it works after I get my tie rods sorted out.