Why does a 32u4 board only have 17 pins?
As others have pointed out, for a standard grid matrix the most pins you can have is to get as close to a square as possible aka FLOOR($pins / 2) * CEIL($pins / 2) - for 17, that can be 8 * 9. This can require some funky wire routing but is functional.
The issue with more advanced input scanning methods is that they require additional hardware - resistors, chips.
I would just spend $5 to buy an Arduino Pro Micro from Aliexpress. That'll have enough pins.