As I have repeatedly observed, these days I mostly go to conferences to which I am invited, and to most of these I am invited as a keynote speaker. This is always very flattering, and that's why I have such problems saying no, which I should do in two cases of three. Apart from being flattering it is also mostly interesting things I am invited to. Things that make you think: Wow, that's exciting! And before you know you have promised to do a keynote, some time in the distant future, with a slight hope that something might interfere. Either the king or the donkey will die, if you know the story.
I try to accept only invitations that are directly relevant for my current research, but this "Wow, that's exciting" thing is highly stretchable so every now and then I succumb to something that is off my path, and sometimes it is an open invitation when I can talk about anything - that's the most difficult ones.
There are two ways to prepare a keynote talk. The easy way is to take something ready. The audience at a large conference is likely not to have heard you before, and if there is a specific topic you can always squeeze in a couple of examples to illustrate it. You can even say: Now, you may wonder what this has to do with the topic of our conference... and then say something convoluted that will make people confused and uncomfortable enough to ask questions.
A more challenging way is to take the opportunity to explore something new. The conference is in the distant future, and you think that by then you will certainly have done all that research, and the keynote will fit neatly as a chapter in your coming book. Ha! The conference is over you before you know. You have promised this keynote, and very soon they ask you for a title to put on their website, which isn't a huge commitment and can be nebulous; but soon after that they ask you for an abstract to put on the website, and this is more of a commitment, especially if the topic of the conference is so narrow that there will be other papers you don't want to overlap with.
Then you re-read the books by the author who is the subject of the conference. You had vague memories of them, but of course they are not at all what you remember. Fortunately, they are not hopelessly bad, and you think that you just about might be able to do what you have promised in your abstract. Weeks and months go by, and you still hope that the donkey will die, but the silly animal isn't cooperative, so one day you simply have to write this paper, and you cannot take something ready because you haven't ever written about this author. You re-read the books again and realise that there is nothing useful in them in terms of your current research because at the time you agreed to do the keynote you had no idea what your current research would be. You are desperate. You go and dig in the garden. You read unrelated books. You grade student essays. You make your family's life miserable. You procrastinate. You grade more student papers. You cannot do anything sensible because the paper is hovering over you.
Then one morning you sit down at your desk, feeling like a prisoner, and re-read what you have written under torture, and suddenly it all makes sense, and you just need to delete half of it and write a new half, and it turns out to be quite a good paper, relevant to your current research, original, clever, a paper to be proud of.
Of course I know that part of the scenario is that when I re-read it tomorrow it will be a horrible paper, banal, incoherent - a paper to be ashamed of. But that's transitional as well.
PS The king and the donkey story appears in Arabian Nights and many other folktale traditions. A trickster makes a bet with a king that he can teach a donkey to talk in just ten years. When his friends wonder how he can venture such a bet, he says: Well, who knows what happens in ten years? I may die, the king may die, the donkey may die...