Here’s a guide for creating a MIDI keyboard from a cheapo toy keyboard.

This project details the steps to build your own Open Source (musical) keyboard which connects to a computer via USB and sends MIDI signals. This is achieved using an AN2131 development board. The AN2131 is now discontinued, so development boards can be bought cheaply on eBay. Alternatively you could use another USB microcontroller, if you are able to port the firmware. You could also hack any EZ-USB based device, of which there are many.

The walkthrough also covers interfacing your open source midi keyboard with Linux using the Bristol synth emulator. Pretty neat stuff.

How to Build an Open Source MIDI Keyboard – Link