The main thing that could help you is that for passé composé the action happened and is finished.
Passé composé is used to answer the question “What happened ?”
Imparfait is used to answer the question “What happened during the action ?”
For your exemples :
J.K Rowling a écrit Harry Potter
She finished to write Harry Potter, the action ended –> passé composé
Isn’t this continuous and don’t we know the exact “moment” when she wrote the text ?
You would use “écrivait” if you indicate “where”, “when” or “why” at the end of the sentence.
Exemple : J.K Rowling écrivait Harry Potter durant les nuits d’été.
Nous jouions aux échecs depuis un bon moment
They’re still playing –> imparfait
Maybe this links could help you more :