I think it might help if you gave some examples of the kind of sentences that are giving you trouble. I can think of examples of "when + infinitive" like "He doesn't know when to be quiet", and "when + gerund" like " When sleeping is difficult, try counting sheep", but is this what you're talking about?
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.
Anonymous not talking about certain cases just asking in general..
hahha. Limiting the discussion to when + gerund/infinitive is already quite specific.
Unfortunately, it'll come down to "certain cases." hahaha.