The USB HID protocol isn't encrypted. You can literally just add a pass through that logs (or transmits) the data.
You'd have to check your USB connectors for a small extra dongle every time you boot up with just what is consumer-available[1]. There's also this type of stuff that can be wired into a keyboard[2], obviously harder to detect but a bit more involved to install as well.
With a national R&D budget you can without a doubt do much better than both of these.
[1] https://www.keelog.com/airdrive-keylogger/
[2] https://www.keydemon.com/en/keydemon/28-1576-hardware-keylog...