That doesn't really work, as it sounds like you are talking about the literal experience of taking (swallowing) the pills, and not about what happened to him afterward. "When he took" is much better.
So when are you used to say "in + doing"?That sentence is conceptually correct (because the scraping was how he hurt it), but unnatural. We would probably say:
He hurt my arm when he scraped it against the rough wall.
He hurt my arm by scraping it against the rough wall.
I think that using "in doing" as a temporal reduced clause is a literal translation from Portuguese to English but it doesn't work well.So when are you used to say "in + doing"?