Everything they did was very carefully rehearsed over and over. They had the skill and timing to make it look like they were ad-libbing.
Saw a programme a year or so after Eric's death, where Eddie Braben was talking about what it was like working with the pair. He talked about the famous piano sketch, featuring Andre (Mr Preview) Previn, and said that Eric in particular spent HOURS just walking backwards and forwards on the set, moving the piano and stool backwards and forwards, tripping on different steps, until he was satisfied that he had made the whole thing as funny as it could be. Braben said that this was fairly common.