I didn't have a MIDI keyboard, just a really old digital keyboard with no digital interface...yet. I took the old one out and cracked it open, then monitored what every key press signaled on the internal PCB and slowly reverse engineered the pattern (spoiler: it's multiplexing!).
I later stuck an Arduino inside the keyboard to monitor the signals, and updated the Arduino UNO's comm chip firmware to act as a MIDI device, and exposed the Arduino's USB port on the back of the keyboard. The Arduino sends the appropriate MIDI message from the signals it monitors. Read the full build here: https://medium.com/@mero11.gh/midi-fying-an-old-casio-digital-keyboard-6a9ae9f3092b
I'm going to nitpick(sorry) and point out that an octave covers only one scale! which in this case is 7 consecutive white keys (so in our case it would cover 12 keys (7 white + 5 black)).
I believe the division to sections of 4 with 8 keys(notes) is that any other combination would need more wires.
Nitpick all you like - I'm not exactly musically inclined. I thought an octave would be eight keys of any color, but I guess it's just a convenient factor of 32 keys on the keyboard.
Just read the article, pretty clever how they multiplexed by octave and note. And good job decoding that on the cheap.