To query the buttons, I use a library which, among other things, takes over the debouncing of the buttons. You can read how the library basically works under the link that is deposited next to the #include<Button_SL.hpp> satetement as a comment.
In line 43, an object is initialized in an array for each pin to which a button is connected.
In this way, each button can be queried in a loop in the “checkButtons()” function. If a button is pressed, its position in the array is returned. In this way, it is always possible to determine which button has been pressed...