How to extend a microcontroller GPIO to ~300 inputs?
If 256 buttons will be enough, you can use two MCP23017 (16 port I2C GPIO): the first one as 16 outputs, the second one as 16 inputs, of course with 16x16 matrix of buttons.
If not enough, you can use three of them, or "borrow" additional three lines form MCU (so, it will make 16x19 = 304 buttons possible).

As @jonk mentioned, if you want to detect multiple buttons pressed at the same time, you need to add diodes (1N4148, 1N914) to each button, like below:



If you don't need to handle multiple pressed buttons, you need to protect only the output lines by diodes, like below:



MCP23017 is pretty cheap and works very well.