Keyguard for a PC Keyboard

A keyguard for a PC keyboard is fundamentally a sheet of plastic with an arbitrary set of openings cut in it.  One for every key on the keyboard.  That means it qualifies as a “free-form” keyguard.  More about free-form keyguards here.  You must use OpenSCAD and the full version of the keyguard designer to design a free-form keyguard.  To learn how to download OpenSCAD and launch the full version of the keyguard designer go here.

Such keyguards are typically too wide to print on a 3D printer (though, in a pinch, you might be able to split it in half and then glue the halves together after printing).  In the end, the keyguard will very probably be made of laser-cut (or CNC milled) acrylic.

Designing the keyguard

As an example, we’ll design a keyguard for this Dell keyboard:

Next we’ll turn to the keyguard designer and select some items from the Customizer pane.

First choose “Laser-Cut” from the “type of keyguard” pull-down list:

Also choose “no” from the “use Laser Cutting best practices” pull-down list so we have complete freedom.

From the “Tablet” section, choose “blank” from the very bottom of the “type of tablet” pull-down list:

Ignore what you see in the display pane.  We’ve got a couple of necessary steps to take first.

We’re going to use tablet case measurements as the core of our design.  That’s where all the openings for the keys will be cut.  So we’ll focus on this part of the keyboard:

That region measures 118 mm high and 432 mm wide:

Those measurements become the size of the case opening.  Go to the Tablet Case section and choose “yes” from “have a case”.  Now set the “height of the opening in case” to 118 and the “width of opening in case” to 432 .  Leave the “case opening corner radius” set to 0:

Finally, set the “number of columns” in the “Grid” section to 0:

Now the model in the display region looks more representative, though still not like much:

It’s 118 mm high and 432 mm wide.  Here’s what it looks like from above:

If you start cutting holes now you’ll produce something that’s pretty ragged:

This will cause some problems in a little while from now and isn’t what the final keyguard will look like, so before we start cutting we’ll add a border around the “case opening”:

This border is 10 mm wide and has a 10 mm corner radius (your keyguard may be different):

This border is called a “case addition” and the instruction to add it to your design gets placed in the “case_additions” data structure in the openings_and_additions.txt file.  The instruction looks like this (click on the image below to expand it):

The border is created by adding a large rounded-rectangle ( “rr”) to the case opening.  The addition is 138 mm high (118 + 2*10) and 452 mm wide (432 + 2*10).  It also has a 10 mm corner radius.  You specify the location of this rounded rectangle by specifying the x and y coordinates of its center.  When measuring for case additions, all measurements start at the lower left of the case opening.  The center of the case opening is 216 mm (432/2) from the left and 59 mm (118/2) from the bottom.  So the x value is 216 and the y value is 59 in the case_additions instruction. 

Save the file and the display updates to look like this:

It will be hard to see the border until we start adding openings for each of the keys on the keyboard.  Get a good metric ruler and place it on the keyboard.  Align the left edge of the left-most key with the zero point on the ruler:

The left edge (i.e., the “x” value) for the “Shift” key will be “0”.  Measure the right edge to get the “width” of the Shift key:

Here, we’re measuring the top of the key to determine its width since that’s the easiest measurement to consistently take.  You can add to this number later so that the opening will be wider and easier to get a finger through if necessary.

Now, record the left side (i.e., “x” value) of the “Z” key:

Measure the right side of the key and subtract the value for the left side to determine the “width” of the Z key:

You’ll find that many of the keys (certainly the letter and number keys) are exactly the same size (width and height).

Now measure the height of the bottom edge of each key (i.e., the “y” value) as well as the “height” of each key:

The “y” value for the keys in the bottom row will all be “0”.  In fact, because the keys are nicely arranged in straight rows on most keyboards, the “y” value and “height” value of all keys in the same row will be the same.

Note that the keyguard designer won’t work for you if you have a keyboard that curves the placement of the keys or has odd shaped keys.

It can help to have a second person record the measurements while you read those values off of the ruler.

We find it useful to record these values in a spreadsheet (in this example, Excel):

Spreadsheets are very good at copying values from one cell to many others.  They are also good at incrementing values in one column by a constant.  That can be helpful if you want to move a row of key openings uniformly in one direction or another; or increase the size of the openings consistently for all keys.   Subtracting a constant from the values in the “x” column moves all openings to the left by that amount.  Adding a constant to all the values in the “width” column increases the widths of all openings by that amount.

Format your spreadsheet like the one above.  The first column should contain values that start with a left square bracket, followed by a few letters contained in double quotes that represent the key.  [See the comments on what makes a “good” double quote, below.]  The designer ignores this first column but putting a label there will be very handy when you want to change a measurement for a particular key.

The last column contains only a right square bracket.  There is nothing in the column labeled “other”.  The background colors are just there to help us easily see all the keys in the spreadsheet that correspond to a single row of the keyboard.

Each row in the spreadsheet will become an instruction that goes in the “case_openings” data structure.  To prepare the instructions the rows must be converted to plain text and a comma has to be inserted between the cells.  The best way to do that is to use a word processor.  We’ll copy the rows of the spreadsheet (except the header in row 1) and paste them into a word processor (in this case Word):

Next, we’ll convert the table to simple text by inserting a comma between the elements in each cell:

Now you have lines of plain text.  You need to put another comma at the end of each line, after the right square bracket:

In Microsoft Word, “^p” represents the paragraph mark at the end of each line.  This will put a comma at the end of each data line including the last one (as well as an extra paragraph containing only a comma):

Go in and remove the last two commas:

Copy all the lines in the document.

Open the “openings_and_additions.txt” file and select all the data lines in the case_openings data structure:

Now paste the contents from the document:

The data items don’t align with their headings but they will still work just fine. 

Save the  “openings_and_additions.txt” file and return to keyguard.scad.  Your model should update automatically:

On the other hand, you may not see anything in the display pane and there will be an error message in the Console pane:

One of two things has probably happened.  Either you didn’t remove the extra commas at the end of the data lines, or you’ve accidently included some “bad” double quotes in your data lines.  Document editors like to insert special characters that serve as double quotes:

You can spot these “smart” quotes because they don’t look exactly the same.  The one on the left slants to the right while the one on the right slants to the left.  OpenSCAD doesn’t like “bad” double quotes. 

“Good” double quotes look like this where both are exactly the same:

The nice thing about using the spreadsheet to insert these quotes is that the spreadsheet only knows about “good” double quotes.  They then carry all the way through the document editor and into the openings_and_additions.txt file.

Before you laser-cut your design, it’s a good idea to test it.  You can do that by 3D-printing the first two layers of your design and lay the print on top of your keyboard to test how well the openings in the keyguard align with the keyboard keys.  Two layers are enough to create a sturdy mask that you can use to test the layout of your keyguard.

You probably don’t have a printer that can print a keyguard as large as this so expand the Special Actions and Settings section and set “generate” to “first half of keyguard”:

Now scroll to the bottom of the Special Actions and Settings section and set the “first two layers only” to “yes:

Assuming that you set your slicer to print 0.2 mm layers, the print will complete after printing the first two layers – a total thickness of 0.4 mm. 

The display pane will look like this:

If you see something that looks like a full thickness keyguard or something distorted like this:

Just use the mouse wheel to scroll out and away from the keyguard and you’ll see the keyguard displayed properly.

Render and export the STL of “half” of the keyguard.  Load the STL file into your slicer, set the layer height to 0.2 mm, and print.  Repeat the process with the “second half of keyguard”.

You can compare the two-layer masks directly to the keyboard:

Or, better yet, use a little masking tape to hold the two halves together and get an even better feel for the fit:

If you have a really large keyboard, or a really small printer – or if you just have a troublesome part of the keyboard where you need to repeatedly change the data and reprint and you don’t want to take the time (or plastic) to print more than you absolutely need to – you can print an arbitrary region of the keyguard.

You need to provide two pieces of information – the coordinates of lower left corner and upper right corner of the rectangle you’d like to print.  In the Special Actions and Settings section you will find two options:

The “trim to rectangle lower left” option is where you put the x & y coordinates of the lower left corner of the rectangle.  The “trim to rectangle upper right” is where you put the x & y coordinates of the upper right corner of the rectangle.  Be sure to separate the coordinates with a comma and put them between square brackets.

When we apply these values to our example keyguard, we single out just region containing the arrow keys and the cursor positioning keys:

To display the entire keyguard again, change both options back to “[0,0]”:

“Rinse and Repeat”

Repeat this process of changing the data, printing masks, and comparing masks to keyboard, until you have just the fit and opening size that you want.

Note that you can be a precise with your measurements as you want in the .txt files.  The precision of your printer, laser-cutter, or CNC mill, set the limit for how precise the process can be.

Now set “generate” in the Special Actions and Settings section to “first layer for SVG/DXF file”.  Render and export your model as an SVG file for laser-cutting.

Related Topics