A wandering mind can lead to accidents and lost productivity. Now, a study finds that real-time brain monitoring can be used to help people regain focus.

Neuroscientists at Princeton University monitored the brain activity of students who were asked to perform a repetitive task that required close attention. While lying inside an functional magnetic resonance imaging, or f.M.R.I., machine, the students were shown a series of pictures of human faces superimposed over scenery. They were told to press a button when they saw a particular kind of face (female or male) or when they saw a particular kind of scenery (inside or outside).

The test was designed to mirror the kind of everyday task from which one could easily lose focus, said Nicholas B. Turk-Browne, the lead author of the study. “What makes this a study of attention is they needed to select the image that’s relevant and ignore the other part,” he said.

As the students performed the task, the researchers monitored their brain waves for signs that they were focusing on the wrong thing. When such a signal was detected, the researchers made the task more difficult. The students soon learned to recognize signs that their attention was lagging, and their performance improved.