geekhack Projects > Making Stuff Together!

[BUILD] Magic Keyboard 2 but mechanical

(1/6) > >>

Hello Geekhack!
This topic was originally opened on the LTT forums, but I decided to move it here because it felt more appropriate.
Unfortunately, there wasn't much engagement on the thread over there, and I thought you guys, here, might be more interested in this project.
This post will bundle the two posts I made on the LTT forums into one. Shortly after this, I will post a new one with the latest updates.

(Post 1)
Hi guys!

I'm Nathan, a French back-end software engineer by day and electronics enthusiast by night. Currently, I'm in the process of reverse engineering the new Magic Keyboard 2 from Apple.

You might say:

> Yeah, but for what? That's just silly and a waste of time...

Well, I want to transform the Apple Keyboard into a mechanical keyboard.
I plan to dismantle the entire keyboard, keep the main logic board, reverse engineer the matrix and other components, create my own PCB, connect it to the Apple board, and voila! A Mechanical Magic Keyboard is born. Or as I like to call it, the Magicanical Keyboard (funny, right?!).

> Ok, fine, but I still think this is silly. Couldn't you just build a Bluetooth board and call it a day?

And I would answer:

> Nooo!!

These new keyboards come with a built-in fingerprint sensor, known as Touch ID. As a Mac user (you can boohoo me if you want), both at home and work, I frequently use docked Macbooks. So, having a keyboard that is seamlessly integrated into the Apple ecosystem with easy pairing, Touch ID, battery indicator built into the OS, and more would be fantastic!

Here's a rundown of the tasks that need to be done: (Done ✅, To do ❌) (Updated 2023-10-05)

- Teardown the keyboard ✅
- Figure out the functionality of each component ✅
- Determine how the keys are connected to the microcontroller (whether it's a standard scanning matrix or something else, considering it's Apple after all...) ✅
- If it's a standard scanning matrix, understand how key presses are detected (whether the matrix is resistive or capacitive) ✅
- Plot each key's row and column ✅
- Create a development board to verify the theory ✅
- Debug/test the development board to ensure everything is functioning correctly ✅
- Search for a keyboard case that can accommodate my custom board
    - If I can't find what I want, design one from scratch ✅
- Determine how to fit the Touch ID sensor into a keycap ✅
    - If I can fit it inside a keycap:
        - Reverse engineer how the button under the Touch ID sensor is connected to the main board. ✅
    - If I can't fit it inside a keycap:
        - Figure out where I can fit this sensor!
- Create the final board and custom flex PCBs to go with it ❌
- Find macOS keycaps ❌

If I have time, here are some additional cool things I'd like to do:

- Replace the lightning connector with USB-C ❌
- Add per-key backlighting with a sleep timer
  (This would require in-depth reverse engineering of the Apple board, so it may not be doable) ❌

> Okay, that seems like an interesting idea... When you're finished, could I replicate the project?

Absolutely! The project will be fully open-sourced when it's completed.

So, are you pumped for this? Let's get started!

1) Tearing down this bad boiii

I got this second-hand keyboard from LeBonCoin (the french equivalent of Craigslist), for 70€.
It was essential for me not to destroy a brand new keyboard, and if you decide to replicate this project in the future, I hope you'll consider using a second-hand keyboard (ones with spilled coke and sticky keys are perfect! 😛).
I'm passionate about making the world as sustainable as possible, so repurposing broken keyboards is the way to go!

Mine came with a broken key (damaged scissor mechanism and missing a keycap).

Front of the magic keyboard:

The back:

Removing the plastic rear cover was a NIGHTMARE. It took about an hour and a half and two bloody fingers to remove it! The surface was covered with a lot of glue, so I had to use a trusty hair dryer, guitar picks, a box cutter, and an old fidelity card to remove it.

Here's the "lot of glue":

If you decide to tear down your own keyboard, be careful not to insert your prying tools between the back cover and the plastic reinforcement plate. Instead, insert them between the back cover and the plate.

Here's a picture to illustrate what I'm talking about:

After applying heat, cutting the glue, and gently pulling the cover to avoid breaking it, I thought I could proceed with the reverse engineering without damaging anything. Silly me! 😄

The backing was finally off, and I needed a coffee break at that point. 😅

Yes, I know some screws are missing in the picture, but my camera decided not to focus properly. This is the only clear shot I have of this step.

Next, I removed all the small torx screws, disconnected the battery, and the plastic frame was finally free. And boom! We finally arrived at the interesting parts—the electronics!

Let's take an overview of what's going on here:

Now, let's try to remove the logic board from the chassis, and here's where the trouble began (unfortunately, I didn't have much footage of the following parts).

While attempting to remove the sticky tape from the keyboard matrix connector, I accidentally broke the upper part of the connector. At that moment, I naively thought:

But that wasn't the end of it! The back of the ribbon that plugs into this connector was covered in double-sided tape, which I didn't know at the time. When I tried to remove it without heating up the tape, I broke a small plastic bit that locks the connector. 🤦‍♂️

Here's what it looked like afterward:

Well, it seems I'll need to replace this connector now. Or maybe not. We'll see. Perhaps I'll just solder a flex cable directly to the main board.

Now that all the components are extracted from the chassis, I still don't have access to my matrix. At this point, it's time to bring out the big guns!

I need to remove the little plastic film that is glued to the aluminum frame. I believe this is to prevent crumbs, water, or any other debris from entering the keyboard.

To get this structural layer out of the way, I tried to create a lever using my small flat screwdriver at the solder points.

And it worked! After peeling away all that aluminum, we finally reach our goal. Here's a reconstruction of what it looked like:

It appears to be a basic keyboard matrix with rows and columns, without any Apple shenanigans involved!

The plastic matrix!

> Yeah, this project is going somewhere!!!

2) Let's take a closer look at this matrix

As we can see in the previous picture, it appears to be a classical resistive membrane keyboard.

Here's a schematic of how it works (Courtesy of Deskauthority):


The dome puts pressure on the top membrane, which deforms it and makes contact with the bottom membrane, completing the circuit. So, in theory, all I need to do to make it work is to figure out where each key connects to the 40-pin connector we saw earlier. And that's exactly what I've done!

"Thanks, Apple, for this choice. If the matrix were capacitive, I would have killed the project. In that case, I would need to delve deep into the Apple mainboard electronics and firmware to figure out what's going on and buy a fancy ESR meter to measure the precise change in capacitance when a key is pressed."

3) Tracing the connections

To identify the location of each key on the matrix, I scanned the matrix using my printer.

There was a small problem: the area where the pins are exposed is not translucent, so I couldn't determine where each pin goes. Luckily, Apple used tape for the reinforcement, so with the tip of a razor blade, I could peel it off.

That's better!

Before proceeding with the entire process, let's test our previous theory by simulating a "1" keypress.
I traced the two pads back to their respective pin on the matrix, masked every pin that was not the two I wanted to bridge on the connector, and bridged them using a male-to-male DuPont cable. AND IT WORKED!

(Once again, a reconstruction of what I did at that point)

An army of "1"s started appearing on my screen!

Now, after letting my sanity slip away for hours on end, I traced every trace on this flex board...

And ended up with this magnificent wallpaper!

I was so proud of myself at that point... but a crucial part was still missing...
I needed to plot each matrix position on a spreadsheet. sigh

So that's what I did... and now I can attempt to replicate it on a custom development/validation board.

But that will be for next time...

(Post 2)
Welcome back!

A lot of progress has been made since the last post, and the project is still going strong!

First of all, here's a table showing the two pins for each key.

I'm including this table because I realized it was missing before.

To validate my reverse engineering work before making the final PCB, I've created a development board to reproduce the matrix.

To get a rough idea of the voltage of the CAPS lock LED, I measured it with my multimeter, and it showed around 3.2V.

This was my first time using KiCad, and I switched from Eagle due to the recent changes in Eagle's payment scheme. KiCad's free and open-source nature, along with its strong community recognition, convinced me to switch.

So here's the schematic:

I didn't connect CAPS_LOCK_LED_- to ground because it doesn't seem to be connected.

As you can see, I've done my reverse engineering work on a French Magic Keyboard, and it seems that this work will be compatible with all magic keyboards that have 88 keys—heck, even the 87-key one. After carefully examining every layout on Apple's website, I noticed that only the US and Chinese versions have one less key. It's likely that Apple initially designed the 88-key layout and then removed a key from the matrix for the US and Chinese keyboards.

What's even more intriguing is the similarity I noticed in the connectors on both motherboards—the full-size one and the ten-key-less (TKL) one. Although I haven't reverse-engineered the larger keyboard, I speculate that Apple might have taken the matrix from the bigger keyboard and removed unnecessary keys to create the TKL version.

Considering both connectors have 40 pins and look identical between the full-size and TKL versions, it's reasonable to assume that the matrices might be the same across both keyboards. On my TKL board, I observed several pins on the connector being connected to ground, indicating unused connections. This similarity and the presence of unpopulated pins support the notion that the matrices are likely the same across both the full-size and TKL versions, regardless of the regional layout.

If you closely examine both boards, you can see the same connector on both the TKL and full-size one (Picture courtesy of SnazzyLabs).


For the curious ones among you the connector is the FF14A -40C -R11DL-B-3H from DDK.

After the schematic, here's the dev board layout:

For the FPC connector, I've used a random 0.5mm pitch connector from the KiCad library.

You might ask:

> Why did you put four plated holes for each key? A switch only needs two...

Yeah, you're right, but I added the extra plated holes because I want to put dupont male headers on the top two pins and use a dupont cable with a diode to try to find the "direction" of the matrix.

If I can figure out which pin is the row and which pin is the column, I could add a diode to each key to prevent key ghosting from happening at the hardware level. Though I suspect Apple might have used a fancy algorithm to avoid that at the firmware level or simply limited the number of keys that can be pressed simultaneously. I haven't tested that yet before tearing down the keyboard.

Now it's time to send those boards to PCBWay and wait for them to arrive.

Stay tuned for the rest of the project!

Hello again! :)
Here's the second post I was talking about in the first post.
This one isn't a repost from LTT forums but a brand new one, with new updates on the project.

A few days ago, I received my PCBs from PCBWay, and I was really, really excited! (I was supposed to receive them a day earlier, but the classic "I wasn't at home when DHL wanted to deliver the parcel" situation happened, so I had to wait another day...)

> Pretty, right?!

Immediately, I wanted to test the PCBs, but the ribbons I ordered from Amazon hadn't arrived yet.

A day later, the ribbons finally arrived, and I thought to myself, "What if, instead of removing my broken matrix connector and soldering the ribbon directly to the motherboard, the connector is still good enough to make a connection with a ribbon cable?"

I had three reasons for this:
- First, I couldn't find the connector ANYWHERE on the internet... (I searched for a few hours, but nothing...) The only website I could find them on wanted me to buy a full reel of 5000 pieces... (I don't need that many... nor do I have the money for it)
- Second, I didn't want to remove the connector because I was afraid it would further damage the motherboard...
- Third, I didn't want to solder the ribbon directly to the motherboard because I didn't think the ribbons could handle the heat of the soldering iron... (And I was right; I tried putting solder on the ribbon, and it melted instantly...) I know I could order special ribbons with polyimide from Aliexpress, but I didn't want to wait another month to receive them...

So, here goes nothing...

After playing with the connector (breaking it even more) and the ribbon, I finally managed to align them and make a connection between the two! Hurray!

No soldering required! And no need to wait for the polyimide ribbons to arrive! I was so happy!

> First time the CAPS LOCK LED lit up! But the connector still wasn't aligned properly... Keypresses weren't registered...

> Difficult to do better :D That's spot on!

I'm going to epoxy or hot glue that connector during the final assembly, but for now, that's good enough!

As you can see in the first picture, for each key, two male dupont headers are present, and there are two empty plated holes below each one. I did this because I wanted to plug dupont cables from my dev board into my breadboard and use a diode to try to find the "direction" of the matrix.

The two cables from my breadboard, with the diode in between, plug onto the headers on my board, and using a piece of wire, I can touch the two plated holes to make contact and simulate a keypress.

But, it didn't work. The only diodes I had lying around were some cheap, no-name diodes I got with an electronic kit, and I think their internal resistance is too high. When I tried them, the keypresses weren't registered...

So I gave up. Maybe I'll buy low-resistance diodes in the future, but it's not a priority right now. After all, Apple didn't use them on the original keyboard. I know it's because it was a membrane keyboard, but still... Anyway, my keyboard is going to work without them, and I could revisit this in the future if I want to.

So, I tested all my keys, and 9, TAB, and Option Right keys weren't registering...

After a few minutes of checking my reverse engineering work on the matrix, I found that I made a mistake when writing the pins down on my spreadsheet.

After cross-checking with the original matrix, the correct pins for those keys are:
- 9: 30 and 1
- TAB: 7 and 22
- Option Right: 24 and 22

So, I corrected my spreadsheet, looked at my schematic on KiCad to see where those pins were located, and I tried to bridge them using a wire. Believe it or not, it worked!

I have fully and successfully mapped the matrix of the 88 key magic keyboard! I was so proud of myself; I had spent a lot of hours on this, and it finally paid off!

> First time all keys working! (Sorry for the quality of the picture; it's a screenshot of a video I made to show my friends; it's the only picture I have of this moment...)
Now, it's time to tackle the Touch ID part! But that will be for another post!

I'm taking this opportunity to ask if someone knows where I could find a cheap plastic case that will fit the layout I've designed for this keyboard. Who knows, if it avoids me making a custom one, that would be great. Even if I don't think I'll be able to use a standard one, because I would need a lot of special mounting brackets for all the bits of the magical keyboard, but hey, who knows...

Here's the layout:

Impressive amount of work!
I take it that your custom PCB is only for prototyping and not going to be part of the final keyboard.

BTW, short right Shift keys in keycap sets are usually 1.75u.


--- Quote from: Findecanor on Fri, 28 July 2023, 01:27:13 ---Impressive amount of work!
I take it that your custom PCB is only for prototyping and not going to be part of the final keyboard.

BTW, short right Shift keys in keycap sets are usually 1.75u.

--- End quote ---

Thanks, man, I appreciate it. ;)
Yeah, the custom PCB I've received is not for the final keyboard; it's just a development board. I recognize I didn't emphasize enough on that.
I'm going to build another custom PCB that matches the layout above. :)

As for the right shift key, I've gone with this size because I wanted to have a small gap between my arrow keys and the shift key. But yeah, if it facilitates the keycap purchase, I'm all for it.
Feel free to suggest other layouts or ideas to help me improve this design.

The only thing I want/need is to keep all the original keys of the Magic Keyboard!

just glanced over the thread but this does look cool.


[0] Message Index

[#] Next page

Go to full version