One of the processes keeps sending a keystroke repeatedly in the background, how to identify the culprit? My system is a MacBook Pro late 2013 running macOS Sierra 10.12.6.

Symptoms:


Occasionally after the laptop wakes from sleep, the system would behave as if someone is repeatedly pressing a certain key on the keyboard.
If I click anything (Apple icon, File, Edit...etc) on the menu bar, the item whose name starts with A will be highlighted repeatedly, B if nothing starts with A, and so on. (Therefore, I assume the keystroke being sent is a number.)
If I press cmd+tab attempting to switch between apps, the focus will automatically scroll all the way to the right-most item.
This doesn't affect all apps. I am able to use Chrome as if there's nothing wrong.


My question:


Apparently one or more of the processes running on my system is doing this. To find out which process / app is sending the keystroke, I am looking for a way or a tool to monitor who is sending keystroke. Therefore next time this happens I can use this to determine the culprit.


Thanks!
It turned out that the culprit was Karabiner-elements, and the issue has been resolved in the latest update.

https://github.com/tekezo/Karabiner-Elements/issues/1828

https://pqrs.org/osx/karabiner/history.html