How'd he do it?
Same way you get to Carnegie Hall.
First... The keyboard is programmed so that "any hit" = "next note in song". I really wish he was hitting keys close enough to the right ones to let me pretend it was talent, but sadly, this is pure trick.
Second... It makes me happy to see Letterman's "stupid human tricks" get the credit for a Leno bit.