A more boilerplate solution would be to use something like ZMK (or a similar "keyboard") OS. ZMK uses Zephyr RTOS and is quite feature-rich. A macropad should not be very difficult to make. Reddit's r/ergomechkeyboards may be a good starting point.
Does Zephyr support ESP32's? I didn't see it listed on their page. I did see an Arduino variant though.