Whenever we use " AO + infinitive " it gives the idea as in English: ON or WHEN + gerund"
Let's try some examples:
Cuidado ao abrir a caixa, pode ter uma bomba dentro = Careful when opening the box, it might have a bomb inside)
Ao tentar falar com o presidente, os seguranças não permitiram = When trying to talk to the President, the security guards didn't allow
Ao chegar em casa, percebi que havia sido roubado = On/When arriving at home, I realised I had been robbed.
It's the preposition A + O (because when you try "to noun" the verb, it goes masculine)
O fazer, o sentir, o temer é como (THE (act of) DOING, the act of feeling, the act of fearing)
Is it clear?