Oliver does this. We're nowhere near a headstand though. I taught it by asking for a back up onto a large low box (laptop box) then shrinking the size and adding height to the box. After he learned to do this well, I would put a small box beside his flank, and clicked for him trying to put his foot on it sideways... that may not make sense, but here's a couple of videos.
This is the first time we tried the cock the leg trick, and we're refining the back onto a box trick
And in this one, both tricks are a little more refined
I haven't got a recent video of either trick, but he does the back leg lift on cue without a prop now, and he's on a much bigger box for his back onto a box trick.