Flipping through the Happ catalog the other day, I noticed that encoders went for $100+ dollars. Since I've been looking at (cheap) methods to hook up buttons and joysticks to a computer for when I build my MAME Cabinet, I believe that an encoder is the way to go for everything but analog controls. However, the price isn't right. Thinking about it, and tearing apart several non-working keyboards for more information, I believe I have come up with a (still untested) method of creating an encoder for the price of a cheap keyboard.
To make a keyboard encoder, take apart a (newer) cheap keyboard. There should be a small circuit board that attaches to the keyboard cable. The circuit is rather simple, a few capacitors, resistors, and diodes, plus a big chip that I am assuming is the keyboard decoder. The rest of the keyboard is two layers of plastic with conductive traces seperated by one layer of plastic without conductive traces. When a key is pressed down, it forces a trace on the top layer to contact a trace on the bottom layer through a hole in the insulating layer. The plastic "connects" to the circuit board by having one edge of the plastic, with the conductive traces, lay on the edge of the circuitboard. To build a custom encoder for the price of a cheap keyboard, all you need to do is recreate the encoder circuit board with that edge replaced with a method of connecting wires to the circuit board. To do this, first carefully unsolder the encoder chip from the original circuit board, as well as the capacitors, resistors, diodes, etc, (although, for the later, you can always cheaply replace them). Now you want to etch a new circuit board that is exactly like the original, except it has a terminal block(s0 to connect to. This is your cheap keyboard encoder.
To understand how it works, you must understand how the keyboard originally works. There are less then thirty connections to the encoder circuitboard. (Lets assume twenty-two for the sake of argument). If we divide the number of connections in half (eleven and eleven), we now have a 121 possibilities circuits that can be made by connecting one member of the first group of connections to a member of the second groups of connections. Since a standard keyboard is 104 keys, this is more then enough permutations for a standard keyboard. Imagine the first group of connectors as being labeled A-K, and the second group being labeled 1-11. G4 would be a conneciton between G and 4, which might correspond to the 'Shift' key. The combinations that define keys aren't in a logical order, it doesn't go A1 = 'Esc', A2 = 'F1', A3='F2', etc. The keys are laid out in a way to prevent key ghosting, which happens when three or more keys are pressed, and the computer thinks another key has also been pressed. For example, if the keys corresponding to A1, A2, and B1 have been pressed, a closed circuit for B2 has also been formed. The best way I've thought of to come up with the key combinations is to take the pieces of plastic that have the traces on them, photocopy them, and then trace each route with a colored marker. Then take the insulating layer of plastic, which has little holes in it, lay it over each copy, and mark the holes. Except for a few holes for screws/structural support, and maybe a few unused holes that correspond to different models, each hole is where a key is located. Through trial and error, one can guess what combinations lead to most keys. Then, its a simple task of downloading one of the few apps out there that tells what key is being pressed, and verifying your results.
Once you have done this, I recommend saving it as a file and keeping a printed copy with the custom encoder. To use with a button, just find the key you want to hook up the button to and then connect each wire to the corresponding connection. A joystick is slightly more complicated, a 4 way joystick will use four keys (one for each direction), and an 8 way joystick will use 8 keys. Analog controllers won't work, and thus cannot be connected, since all of a keyboard's connections are digital.
Of course, to use this with a regular keyboard, you must build a keyboard splitter, but that's another node.
Final notes:
This is an untested method. Try at your own risk. Some keyboards are different. YMMV. Any keyboard that "clicks" when the keys are pressed probably uses microswitches, thus this method may not work. If a keyboard has one or two malfunctioning keys, the encoder may still be good, and the keyboard can be salvaged for this task.