Preposition + gerund
As a gerund clause serves as a noun, it can be used after prepositions:
After watching the movie, I wanted to read the book.
Andrey's parents were against his joining the water polo team.
He stayed at home instead of going to school.
What about going out tonight?
He rushed out of the room without saying a word.
A gerund clause can also be the object of a preposition after a verb, adjective or noun:
Would you prefer eating out to staying in?
They charged him with exceeding the speed limit.
I am sorry for being late.
Sarah is very talented at playing the piano.
Is there any other way of solving this problem?
I had difficulty in understanding her accent.
When to is a preposition, it can be followed by a noun or a gerund:
I'm looking forward to our trip.
I'm looking forward to hearing from you.
I'm used to cold showers.
I'm used to walking long distances.
But when to is part of a to-infinitive, it is followed by an infinitive:
I wish to make a complaint.
He used to smoke.