Keyboard Encoder for MAME Arcade





Introduction: Keyboard Encoder for MAME Arcade

Here I will show you how to make an encoder for a MAME arcade (or similar) from an old USB keyboard that you most likely will have laying around in that pile of stuff you'll never use (I've got 3)

I recently made and published an instructable on a home made arcade machine using a raspberry pi as the brains. I had a couple of questions about the keyboard encoder that I used. Initially I had planned to write a program that would boot to a list with a selection of games to play and the user would use the joystick and buttons to toggle through the list and select a game.

This turned out to be a hell of a lot trickier than I first thought, mainly due to the fact that the keyboard encoder I bought wasn't spitting out any thing that I could easily read in Linux. So I decided to "build" an encoder that would.

Step 1: What You'll Need

An old USB keyboard

Lots of different coloured wires

Soldering iron and solder (optional I'll explain later)

Some sand paper (150grit or higher is ideal but use whatever you have)

Multimeter (optional, but highly recomended, again will explain later)

General tools (screw driver, wire cutters, scissors etc.)

Step 2: What Is the Encoder

Inside every keyboard there will be a little circuit (the encoder) that takes key presses, turns it into a signal the computer understands then shoots it down a wire so the computer can use it. It does this by using a matrix type setup. The way I think about this type of setup is that it's one that has multiple grounds (that are independent of one another) and multiple highs (which are also independent of one another), they are linked together in a way that produces many different combinations. the advantage is you don't need many I/O's to have a large array (say something like all the keys on a keyboard) of switches. This is probably an inaccurate description of how it works but it helps me wrap my head around it and understand it.

Step 3: Getting to the Encoder

You will nee to dismantle the keyboard by removing every screw you can find. Sometimes electronics snap lock clips, if so pry it gently with a screwdriver until you've taken it apart. The encoder will be located usually in the top right hand corner (or wherever the lights are for caps etc).

Step 4: Mapping the Keys You Need

Ok this is where I recommend you use a multimeter as doing it by eye can be damn near impossible (well not impossible but just really really really really annoying) you could also use a battery, wires and a light for this but the multimeter makes life really easy.

Inside the keyboard you'll also notice that there are  two bits of plastic film that kind of look like a PCB separated by another bit of film (usually stuck to one of the others).

There should be dots and lines all over it and you'll need to identify which dots correspond to which keys. the easiest way to do this is to count. So the A key on my keyboard 4 down, 2 across (ESC being 1, 1). so get the position of the keys and then count the dots.

Then use a multimeter to find out where these keys joined up to the contacts. Set your multimeter to conductivity mode (set the beep if you can) place on of the terminals on the dot (say for the A key) and run the other terminal along the contacts until it beeps or acknowledges conductivity. Make a note of which contacts they are. I labeled mine 1 - 13 and A - N and just wrote it down. it also helps to mark out the keys with a marker so you don't forget any.

Step 5: Prepping the Encoder

There is sometimes black conductive stuff over the metal of the PCB. This will need to be removed CAREFULLY with sand paper. Once the metal is exposed clean it up with some paper towel as best you can. You should then go along and tin these with a small amount of solder. You will then need to prep your wires in the same way, i.e strip them then tin them

place the tinned wire on top of the tinned contact and press the soldering iron on it gently, wait until the solder liquefies, remove the iron and hold the wire as steady as you can until id hardens again.

If you're not confident in soldering and don't want to do this you could always use conductive adhesive (eg. WireGel). But I reckon solder would be the better and quicker option as most contact adhesives need to cure overnight.

Step 6: Finished Product

I probably wen a little bit overboard with the wires but I do plan to run a number of buttons and controls. you really only need wires for buttons you intend to use.

In the case of mame up, down, left right for directional controls, Z,X,C,V can be used for buttons and Tab so you can get into options (you might also wanna put in a button for credits)

now all you need to do is hook it up to your buttons as you would a regular encoder. For more information on that you can look here at step 3

2 People Made This Project!


  • Paper Contest 2018

    Paper Contest 2018
  • Science of Cooking

    Science of Cooking
  • Pro Tips Challenge

    Pro Tips Challenge

We have a be nice policy.
Please be positive and constructive.




A programming problem:

I needed a bunch of inputs for a Escape Room program I created. I built the keyboard and attached contacts for letters a thru z. The problem is simultaneous keystrokes need to be decoded...keyboard keys don't debounce and therefore reading several simultaneous keystrokes presented a huge programming problem.

In the end buying a few off the shelf MAMEs was the easiest solution. Each MAME provides 12 buttons and Windows individually identifies each unit via hidusb.sys as a HID (Human Interface Device) with letter designations: A, B, C, etc. Polling inputs are performed by assigning hex values to each EG: 1, 2, 4, 8, 16, 32, 64, 128, 256, etc to each button and decoding the result. If the resulting input for MAME "C" is 7 then buttons 1, 2 and 4 are currently making contact on MAME "C". EZ-peazzy

I have a question, I wanted to know how to wire up the microswitches like I have A8 B5 for A and A7 B5 for W, so do I draw multiple wires from B5?

Hey so im fairly new to electronics and stuff so sorry if question is dumb

but where does the ground wire go?? im honestly not sure.

On this specific setup, there is no ground... The IC on the controller has this. Instead, the pins are split up into sections on 13 on the left and 13 (sometimes 12) on the right. (depending on the IC and or keyboard). Just get yourself a naming convention and stick with it. I named all the pins on the left "A" and "B" for the right. Now short out any of "A" with any of "B" and see what button is pressed. A nice tool is It highlights a key once pressed so slide short all the wires that look at the screen and see which buttons are marked green. If it;s green, the combination works, if its white, then something didn't make contact... So in my case "A8" + "B10" = up... etc...

don't have the keyboard plastic parts, only the actual pcb and usb cable, is there a way to determine which point is which?

you can probably just do the "read" function and start shorting one trace to another

I found this indestructible and found it helpful as it provide me with the idea that this is a solution. That being said I wish I would have none that you can accomplish the same thing using an arduino keyboard emulator software like shown here

... just wanted others to know other possibilities exist. Hope someone else finds this information helpful.


Yeah the arduino HID way is a nice way of going about it. But the idea of this was to up-cycle things you have laying around or can acquire for a few dollars. Thanks for the link too, it might help some people.

Great idea and well explained!