Introduction: Keyboard Encoder for MAME Arcade

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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


peachville (author)2017-02-25

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

AnshumG (author)2016-04-11

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?

THEBROTAKU (author)2015-09-10

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.

OrrinG (author)THEBROTAKU2016-03-08

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...

secretgspot (author)THEBROTAKU2016-02-08

to the ground, I think...

secretgspot (author)2016-02-08

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

Spartan 117 (author)secretgspot2016-02-21

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

MarkS335 made it! (author)2016-02-21

I lost one trace, but it turns out that all of the keys that I wanted to use were on different pins anyways. This was a fun build :) I am installing it into a pedestal style cabinet that I have been working on, but I built a test rig too (The cardboard box).

Rovhell made it! (author)2015-09-25

Hi, fantastic Instructable ! I made some cable management because the solders are really tiny and break easely.

AnEngineersView (author)2015-09-06

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.

nwatson16 (author)2015-05-25

Great idea and well explained!

DavideC3 (author)2015-05-10

Wonderful !!! Great Job :D

gtoal (author)2014-03-20

This is a great re-use of old keyboards. For those with less time and more money, there are a few other ways to get an arcade keyboard for an emulator: the tried and trusted iPac: (downside - PS2 connector - although for dls3491 that's actually an advantage...); the MakeyMakey and the many bluetooth devices from ion which can often be found very cheap (Ignore the $99 price, look around for closeouts or used ones. You just want the controller board)

There are also some newer Chinese encoders for $10 to $20 that I haven't seen myself but look to be what's needed - or

dls3491 (author)2013-11-28

Thanks I am planning to use it on a pc that has a ps/2 connector

dls3491 (author)2013-11-27

do you know if this will work with a ps/2 keyboard ?

Spartan 117 (author)dls34912013-11-27

It should do, can't see any reason why it wouldn't. Of course you'll need to use an adapter if you want to use it via USB, but otherwise it should be fine.

SensusVitae42 (author)2013-09-01

Hi Spartan - I see one of the plastic films only has 8 lines, does that mean you can only use 8 different keys?
I note in your MAME instructable, you only use a total of 8 keys/buttons/letters.
Is that correct?

No you can use more than 8, you can use as many as there are inputs on the keyboard I suppose.

I did use only 8 buttons for play (up, down, left, right, b1, b2, b3, b4) but there are now buttons on it for start, coin/credit and when I stop being lazy and put a second set of controls for another player there will be 1 player and 2 player buttons too.

This webpage does a better job than I do explaining how a matrix works.

Hope it helped if you need more info just pm me

octopuscabbage (author)2013-07-16

Wait, why did you do it like this and not just wire it all up, open a word document, and figure out what each key was mapped too?

Is it just because some inputs aren't valid so you have to map it to a valid input?

Pretty much, there's no point really in using a word doc to find out where up down left righ and ctrl are for example. you can use cmd or terminal etc. and the read command (or equivalent) but it's a lot of messing around. Also you don't need to solder on as many wire as I did to be honest I went a little over the top, so it's probably best to get a whole heap of keys you'll be using and just solder the ones needed. Cheers.

Zenoscope (author)Spartan 1172013-07-20

Hi Spartan, thanks for your instructible, I used a modified version of this technique to help me wire up my own keyboard encoder. I'm making an bartop arcade machine.
I was going to trace the keys out on the membrane, but instead I used a wire stripped at both ends and a program like "testkeys" (from the mame-tools package, if you are using a debian variant) to get the key codes and find out what is being pressed. It will display non-printing keys such as shift and alt as well, and can distinguish between left and right keys, eg left shift and right shift.

Spartan 117 (author)Zenoscope2013-07-20

Cheers Zenoscope. Good luck with the arcade machine. Check out my other instructable where I made one using an old CRT if you're interested

thewildman (author)2013-06-02

Nice work. I wanted to talk to you about using a keyboard in your other instructable but I couldn't due to captcha issues. I wanted to ask if there would be problems holding down multiple buttons at once, since on most of my keyboards it can only recognise two or three keys at once, which may be problematic if yours holding down for example left up, button one and then press button two. I remember having issues with some WASD + other keys in computer games. Gamepads don't have this problem. I've hacked a $3.50AUD one from buyincoins to work nicely. It even had convenient pads to solder wires to! But if the keyboard works then that may be cheapest option from scrap.

Spartan 117 (author)thewildman2013-06-03

I originally tried a cheap game pad I got from eBay but I never got it to talk to my pi so I opted for the encoder. I had thought about the multiple key issue and it could be a problem but my thinking is that the controls on the games that I play are fairly simple, I've never had an issue with them on my computer using a keyboard, so it should ok so long as you only use 1 encoder per set of controls (I will run a little diagnostics pad from it though just for show) if I ever add a second player (which I will when I have the time) I'll use the encoder I bought. Cheers

cj8675 (author)2013-06-02

hey do you happen to still have rhe store bought encoder?
if so id buy it off of you for my next instructable or if you just gave it to me id credit you if you can help me out id appreciate it. from cj

Spartan 117 (author)cj86752013-06-03

I have plans for the encoder unfortunately, you can get cheap ones from eBay that work fine. What did you have in mind for your next instructable ?

cj8675 (author)Spartan 1172013-06-03

im making a cnc bartop. i have a 4x8 shop bot if you want i can cut you out a kit out of mdf for 150 cnc cut, routed edges, primed, painted and assembled. all you would need to do is supply your own buttons, pc, encoder, joystick and monitor

cj8675 (author)cj86752013-06-03

for 500 i can make you a complete arcade

Spartan 117 (author)cj86752013-06-03

It's all good the one I built does the job. Cheers

About This Instructable




Bio: Chemist by trade, hacker by nature. I love making things go boom and making things that have gone boom work again.
More by Spartan 117:Keyboard encoder for MAME arcadeTurn an old CRT Television into a Raspberry Pi Powered MAME Cocktail Cabinet
Add instructable to: