But it looks like the KodeZwerg is a direct access to the Windows infrastructure. Wouldn't that be independent of the Lazarus complier?
Yes. It uses SetWindowsHookExW so that's outside the Lazarus framework.
So it must be something else that's blocking the buttons to the application process (which is what I was saying from the beginning).
If then buttons 4 & 5 work in Lazarus and they stop working at some point, then there must be something interfering with it.
(What's why I also suggested the X-Mouse app to see if that can detect the buttons at the point it's not getting to your app anymore, just to test it.)
If it's just only you app that's eventually denied access to those buttons it seems some security issue, but I can't imagine what.
If it's all other programs too (like X-Mouse) that's denied access then there is something wrong with the buttons/driver itself at that moment.
It's just a matter of investigating what (but we can't do that from a distance and it's hard if we can't reproduce the issue).