One of the processes continues to send a repeated hit in the background, how to identify the culprit?

My system is a late 2013 MacBook Pro running macOS Sierra 10.12.6.

symptoms:

  • Sometimes, after the laptop goes to sleep, the system behaves as if someone repeatedly pressed a certain key on the keyboard.

  • If I click on something (Apple icon, File, Edit … etc.) in the menu bar, the item whose name starts with A will be highlighted repeatedly, B if nothing starts with A, etc. (Therefore, I guess the typing being sent is a number.)

  • If I press cmd + tab to try to switch from one application to another, the focus will scroll automatically to the rightmost point.

  • This does not affect all applications. I am able to use Chrome as there was nothing wrong.

My question:

  • Apparently, one or more of the processes running on my system do it. To find out which process / application sends the keystroke, I look for a way or tool to monitor the people who send the keystroke. Therefore, the next time this happens, I can use it to determine the culprit.

Thank you!