cockpit@hanskrohn.com

+49 171 1959 725

18.04.2019

How To Hack a Keyboard

Sometimes it does not make sense to use expensive I/O devices like the EPIC when you need to connect a large number of buttons on one panel. A cheap alternative is to hack a keyboard. A typical use for the hacked keyboard would be a home built CDU, which requires almost 70 buttons to be connected.

The following description applies to an IBM™ PS2 keyboard, but other brands should not differ much.

When you open the keyboard case, you will find two big transparent films with electric leads printed on them, one film on top of the other. The films have a big conductive contact spot located under each key. Since there are less leads than keys, each lead goes to several keys. The leads on the two films form a matrix. When a key is pressed on the keyboard, it actually compresses the two plastic films, the two contact spots touch – and voila: a keypress happens!

Inside the keyboard you will also find a printed circuit card with a microchip and three connectors for flat cables. The smallest connector accepts a flat cable from the keyboard’s LED’s. It depends on your needs if you use them or not.

The next two connectors on the circuit board connect to flat cables coming from the two plastic films. Assume the second Connector has leads A – H and the third Connector has leads 1 – 16. Each key on the keyboard is referenced by a combination of leads from both connectors, i.e. keyboard key “A” would be “B-1”. It is considered “pressed” when lead B from connector-2 is shortened with lead 1 from connector-3).

The maximum number of combinations between leads of these two connectors is 128 (eight letters X 16 numbers). A standard keyboard uses 105 keys.

The hacker’s first task is to identify and lable the leads on the two plastic films, preferrably the first with letters, the second with numbers (see explanations above).

Then, trace each lead and determine to which key it leads. With that information, you can draw up a matrix that contains all keys on the keyboard with their unique reference, made up from a letter and a number, like A1 or B8.

The photo on the left shows the printed card from inside the keyboard. I rerouted the leads from the flat cable connectors into 2 female DB25 connectors. I did this for easier disassambly in case of need, like an upgrade or a modification.

The cables coming from buttons on a panel – like my CDU – are soldered to a male DB25 connector, so the various components are “Plug and Play” (…well, kind of…)

Wiring may buttons using the keyboard matrix can quickly turn into total chaos. It is a good idea to replicate the matrix in your panel, i.e. to wire buttons or switches in the same order as you found it in the hacked keyboard. This will save many meters of electric cable and allows for easier error checking of your work. Be warned: since the grouping of buttons on your panel will be different from the layout of a keyboard, and wires will go back an forth between buttons, chaos will occur sooner or later – just try to postpone that moment as long as possible!

With all the ugly work done and everything correctly wired, the press of the button wired to B-1 shouldl result in your PC receiving a keypress “A”. That is fine for letters and numbers, but what if you need key combinations like ctrl+alt+F?

The solution I came up with is to use a keyboard macro program. It can run automatically at startup and will produce keypress combinations of any type at the press of a single key. The program I use and found well suited for the task is EZ-Macros.

Comments are closed.