Looks like the event tap is disabled by default (you need to manually define SDL_MAC_NO_SANDBOX when building SDL to get it, which we don’t anywhere).
It’s definitely the capslock code that triggers this notification; it goes away if I comment it out.
Is there any reason we can’t just use -[NSResponder flagsChanged] for this instead of IOKit? Apple docs suggest that’ll work:
https://developer.apple.com/library/archive/qa/qa1519/_index.html
Maybe this goes out of sync if the keyboard focus changes?