I needed a way to attach my Apple Magic Keyboard to my SimLab P1-X racing simulator cockpit. I modeled this up in Solidworks & printed in black PETG from Polymaker. It needs to withstand mechanical movement & retain a tight fit in the extrusion as well as to the keyboard. Something like ABS or PETG is probably best since something like PLA would either snap or loosen too much over time.
The extrusion I had to mount to was bought from 8020.net and is slightly different than the 40 series extusions that come directly from SimLab. If you are attaching this to a different 40 series extrusion, you may have to sand down the extrusion bracket a bit to fitm (or it could end up being a bit loose - YMMV).
The extrusion bracket Is designed to be a tight fit in the extrusion and will take some effort to make it slide in from the end. I had to use a rubber mallet to coerce it in, but then it slid up and down the extrusion by hand easily, though still very snug.
The keyboard bracket has slots in it to pass over the rubber feet on the bottom of the keyboard as well as the power switch on the back edge. It's not as snug of a fit as the extrusion bracket is into the extrusion, but it's snug enough to keep the keyboard snugly in place so it doesn't slide back and forth in the brackets.
The two brackets connect together with a single 5mm x 25mm bolt & nut. I used washers with mine, though you could probably get by without them. Once the bolts are snugged, the keyboard retains whatever angle you place it at and is very secure, with no movement at all when typing.