If a pin varies a little, it may be changing state faster than the device you are trying to measure it with. I would think the code is doing something with the weak pull-ups on the pins. Fiddling with the weak pull-ups would allow the chip to scan the buttons, and the code may even use the ADC to read pin levels.