Hardware Hacking

A note on hacking: Hacking is the art of subverting things. It can apply to software or hardware, and not just computer hardware, though this is a common form. It involves taking things and changing them to behave differently from their intended purpose or behaviour. Hacking as usually referred to in the modern press - the breaking of computer security systems - is only one narrow form of hacking, more precisely referred to as cracking. Here we are only interested in the hardware-modification-style hacking.

 

Hacking a Numeric Keypad

The Guts of the device

Starting with a cheap generic USB numeric keypad:

One cheap generic keypad.

It disassembles as so:

Keypad pulled apart, case discarded

While old (and expensive high-quality) computer keyboards still have individual switches soldered to a circuit board, the cheap stuff has two plastic sheets with conductive ink printed on them. Pressing a button, pushes the pads under the button together, completing the electrical circuit and registering a keypress. Try it yourself - plug in the USB cord, open a text editor and press the pads together between your thumb and finger. (I wrote the corresponding key faces on with a sharpie for reference.)

The next thing we want to do is replace the plastic sheet with wires to the switches we want. Any type of switch will work here as long as they are momentary switches (ie: push buttons), not throw switches (stay on until pressed again). A throw switch may still work, but while it is on, the keypad circuit will be sending a continuous stream of the keypress to the computer (as when you hold down a keyboard key for any length of time).

Assorted push-button switches

 

And now for the Tricky bit...

Decoding the Grid

The keypad circuit works on a grid, with scan lines out and scan rows in. It detects a keypress by sequentially sending a voltage out on each row, and checking for a return voltage on each column. This saves a lot of wiring over having an input for each key. (Full keyboards also do this, but have 8+ rows and columns, which is why I am using a numeric keypad - unless you need more than 16 keys, it is a lot of unnecessary work decoding a whole keyboard grid!)

Logically, the keypad is wired like this:

Nice and simple

The reality can be a bit messier:

Reality is always harder

Above, I unfolded the keypad plastic, scanned it with a black background, coloured in the top and bottom halves, then (in my paint program, GIMP), cut, flipped and merged the bottom back over the top. The end result is a little easier to follow, I hope.

The next step is to work out which keypad key you want your own button(s) to activate and trace the path(s) to the appropriate pins on the circuit board (de-soldering and removing the cable clamp may be of help too, but is not necessary - you can usually solder directly to the pads at the back of the clamp-socket).

From back-tracing the circuit tracks, I got this table (NOTE: the table will be different if your keypad has a different chip driving it or a different circuit-board layout!):

KeyNum / * - 7 8 9 + 4 5 6 1 2 3 En 0 .
Pin 1 6 7 4 1 3 4 5 1 3 4 1 3 4 5 3 4
Pin10 10 10 11 6 6 6 6 7 7 7 8 8 8 8 9 9

If you have wired correctly from back-tracing the keypad tracks, and haven't created any cross-pin bridges when soldering, pressing one of your buttons should send a keystroke to the computer. Note that by default the keypad is in non-numeric mode, so the lower symbols (cursor control arrows) are sent by default. You will have to manually set num-lock to get number keys, or set NumLock-on as the default in the host OS (look in the Keyboard settings).

Assorted buttons wired to the keypad

Above: buttons wired to the '1' and '2' keys. Removing the keypad connector revealed some convenient solder points!

 

What Next?

Now you are sending key presses to the computer from whatever buttons you wired in, you can use those keyboard events to activate software functions. You can either write your own program to monitor the keyboard and react to keys, or much software has an ability to customise keys - for example VLC Media Player lets you set custom keys for Play, Stop, etc. so you can set it up to react directly to the numeric keypad:

VLC Preferences Dialog

If you have a favorite computer game on your computer, you could go all-out and hack a full keyboard to create a custom keyboard array with all the keys in optimal places. For bonus points, make it thematic - sci-fi, steam-punk, diesel-punk, retro-sci-fi, leather, wood, stone, crystal, whatever fits the theme of your game!

Rollover: cheap keyboards (and keypads) have trouble telling when more than one key is being pressed at once (excepting special keys such as shift, ctrl, alt, etc.). More expensive keyboards have a feature called n-key rollover which means each key is scanned separately and any combination of keys can be detected at any time. This is particularly useful for touch typists, where the next key may be depressed before the spring in the previous key has had time to release. The extra circuitry required to achieve this increases costs, hence the lack of the feature on cheap keyboards. Keep this in mind when designing the use of your hacked keyboard/keypad - if one switch is being held on, you might not be able to get signals from other switches until that first switch is released!

 

Hacking a Game Controller

This is essentially the same thing as above, except you are replacing gamepad buttons, which is actually easier, as they are generally not wired in a grid, and there will be no key rollover issues (see above). You may have to solder directly to the contact pads, or you may have existing wiring points you can use.

GamePad circuit board

The above image is a typical Digital gamepad circuit. The two 'antenna' boards are the buttons on the back of the board. These are particularly easy to replace with your own switches! The on-board button mechanism consists of interleaved strips of copper circuit which are pressed down on by conductive rubber pads under the buttons themselves.

If you want to use any included analog sticks for input, you will need to first desolder the stick modules and test them with a multimeter to determine their range - analog sticks are usually two potentiometers (variable resistors) at right-angles to eachother. Then replace them with potentiometers of equivalent range.

Example circuit for LDRSome gamepad chips will work with a range of 3-pin potentiometers by measuring the range across the two outside pins when they start-up and adjusting themselves to suit, so if all three pins seem to be wired in, you may have to do the same for it to work, though it also means that you can be a bit freer with your choice of input. To use 2-pin analog devices such as light-dependent-resistors with these devices you can fudge this by putting a fixed resistor valued at your maximum-range across the outer-pin connectors and then experimenting to find out which outer-pin connector to put the second pin of your device on - the first goes on the middle-pin connector, of course).

Also, a 'shock' controller has the option of tactile feedback via its vibrational motor - obviously, you will have to find out how to control this from your program if you want to use the feature.

 

If you are feeling rich and unadventurous :-P, you can also buy made-for-customisation USB input devices like this. Or at the other end of the spectrum you can go right down to a variety of chips like this.

Where's the Chips!?! See those little black circles of epoxy near the middle of both the keypad and gamepad boards? The chips are under those, wired directly to the board rather than in a chip-carrier case. This shaves a few cents of manufacture and makes it almost impossible to know exactly what chip is in use.

 

Hacking a Mouse

USB-adapted pedal

I had a couple of old stenography-tape-recorder foot-pedals, so stuck an old 3-button mouse in one, wiring one pedal up to each button. Using software to map the mouse buttons to keys I was able to use it to control part of my computer.

Mouse circuit-board in pedal case

You can see that under the pedals, are bog-standard microswitches which connected into the old mouse's button wiring-points easily.

For my itended use, the mouse interface is a bit inconvenient as I have to then use a small program to convert the mouse-clicks to the key-press inputs my program expects. I am considering replacing the mouse circuit board with a keypad or joystick board instead.

But wait, there's MORE! If this sort of thing appeals to you, there is a whole web site devoted to this sort of hacking here. Someone else's take on keyboard hacking as an example.

 

upBack to Glenn's Project page.