- Boot into safe mode.
- In safe mode, try hard to reproduce the issue. With “hard” I mean: if the issue normally occurs every 1 out of 10 I would try it at least 30 times.
- If you are unable to reproduce the issue then you have a high probability that a third thing is involved.
- Reboot in normal mode.
- Try again to reproduce it. Why again? Safe mode does not only deactivate processes and extensions, it also cleans system caches – which is a persistent change.
- If you can reproduce the issue again, then…
- …you have to find the culprit by elimination (unfortunately; but at least you know there is something more involved):
- If you have another Mac try it there. Depending on the outcome, find out which processes are running only on the one Mac, or which processes are running on both Macs.
- I you don’t have another Mac, successively deactivate groups of running processes and check again.
- Intuition might help, but don’t rely on it.
I know, with intermittent issues, like in your case, the elimination process can be very tedious. That’s why Safe mode is so incredibly useful: if in safe mode the issue occurs also, then you can most likely save yourself the whole hassle of eliminating other processes.
In my case it was Yoink. But my issue was a mouse selection and clicking issue, nothing keyboard-related. So I don’t think this will really help here.
Edit:
FWIW, on my machine I’m unable to reproduce your issue. Tried it 20 times or so with BBEdit and SD6, with and without your macro.
Edit II:
You don’t happen to have Karabiner installed, do you? If the issue does not occur in safe mode, then Karabiner would be the first thing I’d try to eliminate.