This is the code I run on my 3x3 macro-pad. The main reason I built it is to provide mouse click buttons next to my Ploopy Nano. I use the maddie keymap which includes code that turns the Ploopy into a scroll wheel when num-lock is toggled twice in 25ms which is why one of the buttons is programmed to do that.
I 3D-printed the macropad using this model, used some left over Kailh midnight jade switches left over from other keyboard projects, hand-wired to a Raspberry Pi Pico. The switches are wired to GPIO pins 0 through 8 with 0-2 across the top row, 3-5 across the middle row, and 6-8 across the bottom.