The humble Arduino can do a lot, but did you know that it can emulate a USB keyboard? With this simple scheme, you can combine those hard-to-remember long keyboard shortcuts into one customizable keyboard shortcut. Here is the end result:

Never used an Arduino before? Check out our guide to first turn.

What you need

Parts of an Arduino Shortcut
Here’s what you need to make this project:

  • 1 x Arduino Pro Micro.
  • Momentary buttons or keyboard buttons.
  • Resistors 10 kOhm.
  • Assorted connecting wires.
  • 1 x 220 ohm resistors.
  • 1 x 5 mm (0.197 inch) LED.
  • 1 x 5mm LED holder.

You will need a very specific Arduino for this project. I use the Pro Micro since they are so small and cheap that you need an Arduino with built in USB-Serial (Atmega32u4) processor. It is possible to build this project with other Arduinos such as the UNO or Nano, however it takes a lot of hard work to re-flash the bios and fiddle to get it working. Clones of other Arduino models usually don’t work at all, but a Pro Micro clone will work too.

You will need one momentary button, one 10k ohm resistor, and an appropriate connecting wire for each button you wish to use. I use Cherry MX mechanical key switches for the actual shortcut buttons though any the switch will do if it is momentary and not latched.

You may need a few other items depending on how you build this. If you want to prototype, you will need a solderless breadboard. It’s worth spending the money on a good one — sometimes they can be very unreliable. If you want to pack this, you will need to buy some cardboard.

Construction plan

Here is how it will work. The Arduino will be programmed to act like a USB keyboard — as far as your computer is concerned. Several buttons connected to the Arduino will send key commands to your computer. You will only press one button, but your computer will think that you have pressed alt > F4 for example.

Switch selection

Arduino Cherry MX

There are several options for the MX series switches. This site is a great introduction, however they come down to noise and pressure. Some models require more force to press, and some models make a mechanical click when pressed. I used Cherry MX Browns which are quiet when pressed. They are all the same size, so choose whichever model you like (or mix and match) without worry.

Of course, you’ll also need to purchase some capital letters, and there are a range of custom designs to choose from — we sourced these from KeyboardCo in the UK.

A business

I 3D printed this case and you can download the .STL files from Thingiverse. Don’t worry if you don’t have a 3D printer, you can still build one. Many websites provide 3D printing services such as 3D Hubs or Shapeways. Also, this is a very simple case, you can make yours out of plastic, plexiglass, wood, or even cardboard. If you want to be really economical, Cherry MX sells a set of testers/samplers on Amazon (UK). You will need 4 M5 x 35mm bolts and 4 M5 nuts. Of course, you can replace them with a suitable alternative that you have.

If you’re making your own case, there’s one important detail you need to know: Cherry MX switches slide easily into their mounting holes. They require a 14 x 14 mm (0.551 in.) square mounting hole, and the plate thickness must not exceed 1.5 mm (0.059 in.). Move too far away from these dimensions and your switches may no longer fit correctly.

Label case
The 3D printing case consists of two parts: top and bottom. Insert Cherry MX switches into the square holes:

Cherry MX Mount Label

Make sure you set the switches correctly. On the top of the inscription «CHERRY», and on the bottom — a small notch. Insert a 3mm LED into this little slot:

Label Cherry MX LED

You may find that LEDs look best upside down. This was the case with the keycaps I used and it doesn’t affect the switches in any way.

You should now have nine switches with 9 LEDs. There is no need to glue any of these parts. Solder holds the LEDs, and friction holds the switches.

Cherry MX All Label

Then, screw on the LED mount (leave the LED removed for now). You will finish assembling the hull later, once the circuit has been built.

Scheme

This diagram is built on cardboard. This is great for building semi-permanent circuits without the expense of a printed circuit board (PCB). It’s just a piece of fiberglass with copper tracks running parallel in one direction. These tracks can be soldered as well as cut. You can cut the track with a special tool or a small drill.

Not too sure about soldering? Look at these simple projects. first turn.

Here is the layout diagram (excluding terminal leads):

Arduino Reduced Board

Make sure you cut traces under the resistors and the Arduino. Since it can be very difficult to read the schematic on the board, here is a breadboard version:

Arduino shortcut layout

It’s a snug fit to squeeze all the components into such a small space. Cut the corners of your cardboard as follows:

Keyboard shortcut

This should fit neatly into the bottom of the case:

Keyboard shortcut in the box

Make sure the tracks are moving vertically.

Connect the anode ( long stem, positive ) of the LED to a 200 ohm resistor and then to +5 V. Connect the cathode ( short leg, negative ) to the ground. Cover the legs with heat shrink tubing and then insert the holder into the LED. There is no need for any adhesive, however your LED holder may not be a snug fit so you may need to adapt these instructions.

Label Status LED

Instead, you can use a two-color LED — this will allow you to set up two or more switch banks with different colored status LEDs for each bank.

Now it’s time to solder all the LEDs for the keycaps. They are purely used to make the keys glow, so you can skip them if you want, and they don’t need to be connected to a digital pin, just for power. Connect all anodes together and all cathodes together. Learn from my mistake — it’s much easier to do this before connecting the switches! Connect the anodes to +5 V through a 220 ohm resistor, and ground the cathodes. These LEDs are connected in parallel. Here is the schematic for just these LEDs:

Button Combination LED Circuit

Use a small piece of heat shrink tubing to close the connection between the LEDs and the Arduino:

Shrink LED label

Turn on the Arduino to check if all LEDs are working. You don’t need to download any code. If any LEDs are not working, go in and recheck the wiring.

LED test label

Now connect the switches. They must be connected through a 10 kΩ resistor or the Arduino will die. This is called a dead short — the +5V goes straight to ground and all that’s left of your Arduino will be a puff of smoke (trust me, I already killed one so you don’t have to). Here is the schematic for one switch:

Arduino Shortcut Circuit

This circuit is the same for all nine switches. Connect switches to digital pins 2 through 10, each with its own 10K resistor to ground. Be careful when soldering Cherry MX switches, they can be a bit brittle, I had a few broken pins. You may want to solder them directly to another piece of cardboard, but the end leads still fit.

That’s it for wiring. You might want to mount a USB type B socket, however the tiny pins on these are often quite difficult to solder. If you don’t want to do this, don’t worry. The Micro USB connector on the Arduino fits snugly into the hole in the case. If you’re a bit confused by the different USB types, make sure you understand the differences.

Finally, double check that the schema is correct. The short one can easily destroy the Arduino, and it can be easily done with cardboard.

The code

Now check if the schema is correct. It’s a good idea to do this before continuing so you can fix any problems while you can. Download this test code (don’t forget to select the correct board and port in the menu Tools > Fee and Tools > Menu ports ):

const int buttons[] = {2,3,4,5,6,7,8,9,10}; // array of all button pins void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(2, INPUT); pinMode(3, INPUT); pinMode(4, INPUT); pinMode(5, INPUT); pinMode(6, INPUT); pinMode(7, INPUT); pinMode(8, INPUT); pinMode(9, INPUT); pinMode(10, INPUT); } void loop() { // put your main code here, to run repeatedly: for(int i = 2; i < 11; ++i) { if(digitalRead(i) == HIGH) { // software de-bounce improves accuracy delay(10); if(digitalRead(i) == HIGH) { // check switches Serial.print ("input"); Serial.println(i); delay(250); } } } } 

You may need to change pins if you have changed the circuit.

Once downloaded, open the serial monitor ( top right > Serial Monitor ). One by one, press each button. You should see on the serial monitor the number of the button you pressed. As with the LED, if your computer complains of too much current or the LEDs go out when you press a button, turn off immediately! You have a short somewhere in the circuit, double check that the circuit is correct and there are no shorts between the connections.

If everything works, go ahead and paste the circuit into the box. You can use some glue to hold the chain in place (although the wires kept mine in order). Screw on the cover.

Making an Arduino look like a keyboard is very easy. If you are using Nano or UNO you are going to flash the Arduino with device firmware updates (DFU). This is commonly used to flash new firmware to the Arduino. You are going to use it to flash the Arduino with new firmware that will make it work like a keyboard. This will not be covered here as it is quite a difficult task. The Arduino website has a good tutorial for this.

The Arduino Pro Micro makes this step very easy. The logic needed to emulate a USB keyboard is already built into the processor, so it's as easy as writing some code!

First set up the keys:

 int keys[] = {2, 3, 4, 5, 6, 7, 8, 9, 10}; 

This is an array containing all the pins to which the buttons are connected. If you have used more or less buttons, or used different pins, change the values ​​here.

An array is a collection of like-minded people. Computers can optimize your code for quick access, and they speed up the process of writing code.

Now initialize all pins as inputs:

 void setup() { // put your setup code here, to run once: Keyboard.begin(); // setup keyboard for (int i = 2; i < 11; ++i) { // initilize pins pinMode(i, INPUT); } } 

This tells the Arduino that all pins in the array are inputs. This uses a loop, so instead of writing pinMode(2, INPUT) nine times, you only have to write it down once. This also calls Keyboard.begin . This installs a function built into the Arduino library, designed specifically for keyboard emulation.

Create a method named readButton :

 boolean readButton(int pin) { // check and debounce buttons if (digitalRead(pin) == HIGH) { delay(10); if (digitalRead(pin) == HIGH) { return true; } } return false; } 

This takes a pin and checks if it has been pressed or not. It just returns TRUE or FALSE . It also contains some software debugging - a simple delay and then rechecking the switch ensures that the button was actually pressed.

Now another for loop is called inside void loop() :

 void loop() { // put your main code here, to run repeatedly: for (int i = 2; i < 11; ++i) { // check buttons if(readButton(i)) { doAction(i); } } } 

Again, this iterates over each element in the array and checks if it has been clicked. This is done by call method readButton, which you created earlier. If the button was clicked, it passes that pin number to another method called doAction :

 void doAction(int pin) { // perform tasks switch (pin) { case 2: Keyboard.println("drive.google.com"); break; case 3: Keyboard.println(".com"); break; case 4: // CMD + T (new tab, Chrome) Keyboard.press(KEY_LEFT_GUI); Keyboard.press('t'); delay(100); Keyboard.releaseAll(); break; case 5: // your task here break; case 6: // your task here break; case 7: // your task here break; case 8: // your task here break; case 9: // your task here break; } } 

This checks the contact number with the operator switch . Operators switch (sometimes called switch case ) are similar to the operator if however they are useful for checking that one thing (in this case the pin number) is equal to one of several different results. In fact, they are much faster to calculate.

The main components are inside this switch statement. Keyboard.println writes text to your computer as if you were physically typing each key. Keyboard.press presses and holds one key. Don't forget to release them with Keyboard.releaseAll after a short delay!

Here is the complete code:

 int keys[] = {2, 3, 4, 5, 6, 7, 8, 9, 10}; void setup() { // put your setup code here, to run once: Keyboard.begin(); // setup keyboard for (int i = 2; i < 11; ++i) { // initilize pins pinMode(i, INPUT); } } void loop() { // put your main code here, to run repeatedly: for (int i = 2; i < 11; ++i) { // check buttons if(readButton(i)) { doAction(i); } } } boolean readButton(int pin) { // check and debounce buttons if (digitalRead(pin) == HIGH) { delay(10); if (digitalRead(pin) == HIGH) { return true; } } return false; } void doAction(int pin) { // perform tasks switch (pin) { case 2: Keyboard.println("drive.google.com"); break; case 3: Keyboard.println(".com"); break; case 4: // CMD + T (new tab, Chrome) Keyboard.press(KEY_LEFT_GUI); Keyboard.press('t'); delay(100); Keyboard.releaseAll(); break; case 5: // your task here break; case 6: // your task here break; case 7: // your task here break; case 8: // your task here break; case 9: // your task here break; } } 

In addition to all the number and letter keys, the Arduino can press most of the special keys called keyboard modifiers . This is especially useful for pressing keyboard shortcuts. The Arduino site has a helpful list.

Now it remains only to create a few shortcuts. You can map this to existing shortcuts like alt + F4 (close the program in Windows) or cmd + Q (sign out of the macOS program). As an alternative, be sure to check out our keyboard shortcuts guide for how to create Windows shortcuts. create shortcuts create shortcuts and each Chromebook shortcut shortcut to to start creating your own shortcuts.

Have you created your own label? Let me know in the comments, I'd love to see some pictures!

Похожие записи