I use a XP-Pen G430S drawing tablet and I am currently using Windows 7 Ultimate SP1. I have the buttons of my stylus configured to right and middle click, and these functions work well in every application. The right click is configured in Krita to bring the pop up palette, and the middle click is configured to start the pan mode. Both functions work well with the mouse buttons, but the same is not observed when working with the stylus. Importantly, the buttons aren't recognized in Krita only when the cursor is on the painting area -- the stylus' right click works fine on the menus, brush presets, tools, etc. The buttons are also correcly recognized as the expected mouse buttons in Krita's Tablet Tester (even though they are recognized as sequential (?) presses, while in the mouse they are recognized as single clicks even when I hold the buttons). The same problem was not observed when working with Windows 10 or Linux (Lubuntu 18.04 LTS).
I'm sorry, but this is not something we can fix. xp-pen's drivers are bad, and apparently extra buggy on Windows 7. Please use a more up to date operating system instead.