There may be a system log file in Console utility that relates to this issue.
Those are very time + date oriented to the partial second, so repeats in a
interval of time may be found, when looking through Console log content.
You may be able to affect a change in this by resetting SMC because a
system function may be acting up and this reset may help what seems
to be a hardware issue; while it may really be at another level.
•Reset the System Management Controller (SMC) on your Mac - Apple Support
Given your model likely is newer enough to not have a user-removable battery
note the instructions in this Support article cover other models as well as yours.
If the battery is non-removable
- Shut down the Mac.
- Plug in the MagSafe or USB-C power adapter to a power source and to your Mac.
- Using the built-in keyboard, press Shift-Control-Option on the left side of the keyboard...
- ...Then press the power button at the same time.
- Release all keys, then press the power button again to turn on your Mac
The section in SMC reset instructions as it relates to what an NVRAM reset affects, is
worth a look; the page link to that reset function is •NVRAM or PRAM.
You may have to take the computer to an authorized Apple service provider or if available
to an official Apple Store where a Genius or expert associate can help you diagnose it &
they could suggest options should further investigation be required. ~ If cause of issue in
either product cannot be re-produced while there, they may not be able to offer a fix either.
If you plan a visit to seek help, by appointment or reservation where available, be sure to
take along the keyboard; and the power adapter for the portable mac. ~ If you can borrow
an Apple USB keyboard, to test this issue, I recommend that to see if it changes anything.
Could be the external keyboard is creating an issue, if it is partially defective.
Sorry that I've not actually helped all that much...
Good luck & happy trails! 🙂