Hardly, scarcely and no sooner

These expressions can be used (often with a past perfect tense) to talk about two events that happen one after another.

Note the sentence structure.

… hardly … when / before …
… scarcely … when / before …
… no sooner … than …

No sooner had she read the letter than she started screaming. (NOT No sooner had she read the letter when she started screaming.)

No sooner had I closed the door than someone knocked. (NOT No sooner had I closed the door before / when someone knocked.)

No sooner can come after the subject. In this case, we use the normal word order.

I had no sooner closed the door than someone knocked.

Scarcely and hardly

Scarcely had I solved one problem when / before another popped up.
Scarcely had I reached the station when the train steamed out.
Hardly had I closed my eyes when the telephone rang.

Scarcely and hardly can come after the subject. In this structure, we use the normal word order.

I had scarcely solved one problem when another popped up.
I had hardly closed my eyes when the telephone rang.

It is wrong to use than instead of when or before in this structure.

Incorrect: Hardly I had closed my eyes when the telephone rang. (Correct: Hardly had I closed…)
Incorrect: Scarcely I had stepped out when it started raining. (Correct: Scarcely had I stepped…)