This SW-18030P breakout makes it possible to use an attached surface as a tap input. An M3 mounting hole lets the sensor be secured to an enclosure or other object so a tap transfers vibration to the sensor.
With one terminal grounded and the other connected to an input with a pull-up, a detected tap briefly pulls the signal LOW. I recommend an interrupt and debouncing because the pulse can be too brief to catch reliably by simple polling.