Is it possible to change pin operation from output to input within the Arduino loop (event-driven)? Is it possible to change pin operation from output to input within the Arduino loop (event-driven)?

I would like to change the operation of a couple of Arduino pins from input to output during execution of the Arduino loop in an event-driven way. Is this possible please?
Yes.

Just call pinMode([pin], [mode]) whenever you want to change from input to output or output to input.

How to decide when to do that is entirely up to you. You can do it any time you choose using any stimulus you like.