Run script on HA from esp32 cpp code (not using ESPHOME)

I am using an ESP32 with an ir receiver to capture button presses on a remote.

Depending on what is pressed, i would like one of 2 HA scripts to run. I am trying to work out the best way of kicking these scripts off almost instantly. I know i could send mqtt messages which could then be picked up by another new mqtt read script to run the appropriate button script. However, i thought there may be delays to this.

I don’t think i can do this in Esphome so any ideas on the best approach?

Do you specifically not want to use ESPHome or are you asking if ESPHome is capable of doing what you are describing?

I use esphome for many devices so am happy to use it. I have now spotted that there is an ir Receiver Esphome option so have started looking at that. I am trying out the learning of codes using esphome now but am finding the available documentation confusing.

Not sure i understand working through protocols and, also, not sure how to interpret the codes i am catching. Having worked with zigbee2mqtt ir blasters, i am used to these codes being long strings of alphanumeric characters. The hex format is very different and would like to see examples of other esphome code that carries out actions based on codes received.