Somatosensation connects animals to their immediate environment, shaping critical behaviours essential for adaptation, learning, and survival. The investigation of somatosensation in mice presents significant challenges, primarily due to the practical difficulties of delivering somatosensory stimulation to their skin as they are in motion. To address this problem, we have developed a method for precise delivery of somatosensory stimuli in mice as they are moving through environments. The approach employs real-time keypoint tracking and targeted optical stimulation, offering precision while preserving the naturalistic context of the behaviours studied to overcome the traditional trade-offs between experimental control and natural behaviour. We demonstrate the method across nociceptive testing to unrestrained behaviour in different environments. We observed that minimal nociceptive inputs can evoke rapid behaviours and these modify movements when stimuli are applied during motion. This method provides a way to explore the diverse roles of somatosensation, from reflexes to decision-making, in naturalistic settings.