- when you know what you should be writing but cannot settle down to it;
- and when you don't know what to do at all.
The second type is hard to address: where do ideas come from, after all? The best solution is avoidance: write down any ideas you might have as you go along. I've got a couple of things that have been on my to-do list for over a year now (Martin Amis book reviews); that's ok, they are there, not going anywhere, and I can move on to them if I finish or get fed up with the more active projects.
But the first type is the main one people mean. It seems so much more attractive to do anything but what you need to. I'm sure that one of the reasons that novelists these days go overboard on research, as if they were writing a text book rather than a work of fiction, is that it's a good way of putting off the fateful moment of having to put it down. From my experience, I think, much as stage fright for actors (which is perhaps a closely comparable phenomenon), writer's block is an expected, perhaps mandatory, element of the writing process; it is therefore not an admission of failure when it occurs. But it is a practical problem, and here are some tips that might help:
write the stuff you want to
I had planned out The Time Zone Rule for a long time but somehow couldn't face the task of scene setting, introducing the characters, and giving them their back-stories: the interesting bit of the story to me was the development of the central relationship from a sexual to a fraternal one. So I decided to start writing there and deal with the introductories later; as it turned out, I left the story in the order written, rather than in chronological order.
If what you're writing doesn't interest you, I don't think it will work for anyone else. One point I realised was that you can use the narrative freedom to describe what you want to: you could describe someone making a cup of tea, if you wanted to, or you could jump straight to the next incident.
If you are inspired to work on something, go for it. I've had several ideas that have jumped the queue because I was ready to advance them. nThat's good, not bad.
If you don't want to apply yourself to the grind of writing a scene or chapter, why not spend some time planning out the plot instead? Although I don't think you have to plan, it provides a great safety net for inspiration and allows you to start building in ironies and hints.
There's a lot of tedious record-keeping, filing, proofreading etc hwich needs to be done; do that instead.
Go through the complete draft elements and see whether they can be improved: they probably can.
go for walk
Define your specific problem: is it a sentence? a character? a plot element?
Then go and do something else and come back with the best solution you have come up with.
Or, of course, you can write something else, like a blog post, rather than get the radio script written (it's a long story, but not yet long enough).