Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Alex Wulff
Published © CC BY-NC-SA

Capacitive Touch Keyboard Extension with Leonardo

Extend the functionality of your current keyboard with custom capacitive touch keys.

BeginnerFull instructions provided2 hours9,368

Things used in this project

Hardware components

DFRobot Gravity Digital Capacitive Touch Sensor
×4
Arduino Leonardo
×1
Male-to-Male Jumper Wires
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Code

PrintChars

Arduino
#include <Keyboard.h>

void setup(){
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  Keyboard.begin();
}

void loop(){
  checkPress(2, 'd');
  checkPress(3, 'f');
  checkPress(4, 'g');
  checkPress(5, 'h');
}

void checkPress(int pin, char key) {
  if (digitalRead(pin)) {
    Keyboard.press(key);
  }

  else {
    Keyboard.release(key);
  }
}

Hotkeys

Arduino
#include <Keyboard.h>

const int delayValue = 100;
const char cmdKey = KEY_LEFT_GUI;

void setup(){
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  Keyboard.begin();
}

void loop(){
  if (digitalRead(2)) {
    Keyboard.press(cmdKey);
    Keyboard.press('c');
    delay(delayValue);
    Keyboard.releaseAll();

    while(digitalRead(2));
  }

  if (digitalRead(3)) {
    Keyboard.press(cmdKey);
    Keyboard.press('v');
    delay(delayValue);
    Keyboard.releaseAll();

    while(digitalRead(3));
  }

  if (digitalRead(4)) {
    Keyboard.press(cmdKey);
    Keyboard.press('n');
    delay(delayValue);
    Keyboard.releaseAll();

    while(digitalRead(4));
  }

  if (digitalRead(5)) {
    Keyboard.press(cmdKey);
    Keyboard.press('z');
    delay(delayValue);
    Keyboard.releaseAll();

    while(digitalRead(5));
  }
}

Credits

Alex Wulff

Alex Wulff

12 projects • 237 followers
I'm a maker and student at Harvard. I love Arduino, embedded systems, radio, 3D printing, and iOS development. www.AlexWulff.com

Comments