If you look at most keyboards they are build like a matrix:
This takes 7 IO pins for 12 keys.
I am using binary coding. This means that I can use 3 buttons on 2 I/O pins, 7 buttons on 3 I/O pins, 15 buttons on 4 I/O pins etc.
Here is an example of a breadboard layout with 7 buttons using just 3 pins on an ESP8266 (Wemos D1 mini).
Besides the few IO pins, another advantage is the easy programming. I added examples in C++ (Arduino language) and ESP-Basic. Could also easily be ported to MicroPython and other controllers like ATTiny85, ESP32, PIC etc etc etc.
Full tutorial, schematics, examples and source code here:
http://lucstechblog.blogspot.com/2019/0 ... -pins.html
Luc