It's not possible include animated content in an Interactive PDF.
However, three other formats that can be exported by InDesign support some version of looping content:
Animated GIFs (supported by FXL Epub, Publish Online, in5 HTML)
Looped Video (FXL Epub, Publish Online, in5 HTML)
Multi-State Object Slideshow (in5 HTML)
Image Sequences (in5 HTML)
I'd do the following if I was making a sizable batch of these gifs:
Record the screen of me typing using any of the tools in Scott's link in his comment above
Import the clips into Adobe After Effects
Create a new composition for each clip and trim as needed
Then I'd use the GifGun After Effects plugin to export them as GIFs.
(There's even an option to ...
On the Windows side, I have used (and still use) Screen2Gif which is freeware and quite effective. I have other more polished tools available for more intensive captures, but for a quickie grab 'n go to gif, it works.
Hope that helps