Multiplexing Inputs on a microcontroller
Charlieplexing takes advantage of tristate pins of the microcontroller, but it costs extra diodes and somewhat more complex programming.

With N IO-pins you can address N(N-1) switches / LED's.

The Charlieplexing with switches article describes how it works with switches and LEDs