Modem sleep, light sleep or deep sleep?
With modem and light sleep, using the above suggestion will work.
Deep sleep does a reset upon waking. If you really want to know the touched pad then you'll need to program the ULP processor using RTC ram/IO. The ULP processor is an ultra low power processor that has RTC slow and fast ram that can retain data through a reboot.
The ULP processor, under the Arduino IDE, can be programmed using the Legacy GNU method, ESP32 API API Reference - ESP32 - — ESP-IDF Programming Guide latest documentation. The ULP processor is programmed using assembly code, ULP Instruction set ESP32 ULP coprocessor instruction set - ESP32 - — ESP-IDF Programming Guide latest documentation.
I use the ULP processor as a 3rd processor to compute some non critical items whose output are made available to the main processor, core0 and core1. An easy example would be to blink the onboard LED, without using the main processor.
Answer, yes it can be done.