Isn't there perhaps a way to multiplex this problem so that you can use a 5x8 matrix (i.e. 13 pins) to allow 40 inputs? Or how about a dedicated chip to do all the heavy lifting for you?
For example, the QT60486 from Atmel offers up to 48 inputs (!!!), perhaps you can make it work with the existing Arduino libraries / code bases for similar Atmel chips (see here: http://arduino.cc/forum/index.php?topic=68129.0
). The only downside to this approach (besides having to learn how to address, read, etc. the chip via SPI) is price, digikey is selling these in a TQFP-44 package for about $9...
From the looks of it, this chip uses a matrix to address its inputs (see http://media.digikey.com/pdf/Data%20Sheets/Quantum%20PDFs/QT60326,%20QT60486.pdf
. Looking at the pin connections, I wonder if the thing isn't a standard-issue Atmel general-purpose processor that happens to be running a capacitative-touch firmware. The connection diagram in the datasheet shows how you could try to interface the Arduino with a matrix of capacitative-touch inputs. Worth a try, anyway.