Skip to content

Technical Design of a Keycap

Bob edited this page Jul 27, 2018 · 2 revisions

If you're going to design your own key profile with KeyV2, it behooves you to understand how a keycap is constructed in this library.

Constituent components

A keycap consists of several key components:

  1. The shape
  2. the dish
  3. the stem/s
  4. the supports

in addition, there are other key concepts to be aware of:

  1. the shape 'envelope'
  2. 'dishing' features

Let's start with the concepts first:

The Shape 'Envelope'

A relatively new concept, a keycap shape is now expected to fit inside of an envelope. That envelope:

  1. is 1.5 times wider and taller than the keycap itself (in the x/y plane)
  2. exactly touches the top of the keycap's dish

note that the envelope has nothing to do with the actual shape of the key. The envelope is the hull of two squares, one representing the bottom of the keycap and the other representing the top.

#2 is very interesting to anyone looking to design a new dish profile. As an axiom, the plane defined by the tilt, skew, and dimensions of the top of the keycap is considered to be the absolute top of any keycap that does not have an inverted dish. that means that if you try to render anything outside of that - the stem, the supports, what have you - it will get cut off and you won't see it. The one exception, of course, is inverted dishing, where the dish is the only thing allowed outside of this boundary.

'Dishing', and 'Inside'

When we 'dish' a keycap, we take its shape, and intersect it with the difference of the dish from the envelope. Confused yet? basically, we take the envelope and subtract the dish from it. Then, whatever parts of the shape fits inside this new envelope is what gets rendered. Primarily, this just takes the dish out of the shape, giving it whatever nice rounded top surface you wanted, but it is also used on the stems. This is to allow for stems that protrude beyond the keycap, like buckling spring stems or datamancer-type keycaps.

Similar to this is the concept of being 'Inside' a keycap, which is about as self-explanatory as it gets. if it fits beneath the keycap, it counts as inside. Supports are currently the only thing expected to fit inside a keycap, since sometimes they would come out the side of the keycap if we just intersected them with the dished envelope.

The Shape

What used to be a single DXF, linear_extruded with a scale parameter, has morphed into one of the most important components of the keycap. The shape is now an algorithm designed to construct a shape from the ground up via multiple slices that are then hulled together. It takes in certain parameters:

  1. size
  2. delta
  3. progress
Size

this is the size of the keycap at the bottom of the keycap. Since most keycaps are smaller at the top than they are at the bottom, this is usually the largest possible size the keycap can be.

Delta

This is the difference between the top and bottom sizes of the keycap. at any given time, a linear shape should be defined as `size - (delta * progress)``.

progress

Progress is how far along the keycap, from the bottom, we are at the current slice, with 0 being the absolute bottom at 1 being the absolute top. This is the algorithmic magic that allows for complex shapes like the sculpted sides of SA / DSA profile keycaps. At 0, some or all of the keycap should extend towards the limits defined by the size of the keycap; at 1, some or all of the keycap should extend towards the limits defined by size - delta. Successive slices of the keycap are hulled together, creating the shape at whatever fidelity you so choose. it's important to note that currently, top skew and top tilt are applied linearly by key.scad. If you really need to, you could counteract this by calculating the progression of each yourself.

The Dish

The dish is the top, rounded part of the keycap, designed to make contact with your fingertips. For DSA and SA keycaps this is a spherical shape, while for DCS / OEM keycaps this is a cylindrical shape.

In any case, the dish shape can be defined as the material you don't want at the top of the keycap, as defined by the top_skew, top_tilt, and top_total_key_width and top_total_key_height. Usually, the dish will intersect all four corners of the top surface of the keycap, though it is not expressly required.

The stem/s

The stem/s are the central stem and support stems, if need be, that connect to the key switch and stabilizers. They must exist under the dish, and inside the envelope. In addition, the stems need to work in concert with the stem supports; if you define a new stem, you should probably update the stem supports to make them work for your new stem.

It's important to note that stems cannot protrude under the keycap. if you wish to render a stem that juts out of the bottom of the keycap, make the keycap taller and only begin rendering a shape after a certain height.

The Supports

The supports are two separate objects: the support structure keeping the stem securely connected to the keycap, and the support structure keeping the stem securely fastened to the build plate while printing.

The current keycap support is an extruded and scaled shape of the stem, pitched at a 45 degree angle. This allows for support-free printing of 1u keycaps while giving strength to the model, and making it harder to snap the stem off. Other supports are available. Supports must exist inside the keycap, which means they cannot be seen from the outside.

Stem supports are small, sacrificial objects to help protect the stem from delaminating while it's printing. They are usually unique to each stem; each stem support file has several different objects designed to work with each stem in the best possible way.