Skip to content

Keyboard Pass through

Owen Schwartz edited this page Jun 27, 2021 · 4 revisions

Useful to modify default keyboard behavior.

Example Script

#include <Keyboard.h>

char key;
char ctrlKey = KEY_LEFT_CTRL;

void setup() {
  //Put your code here to run once
    Serial1.begin(9600); //Start listening for keyboard commands
    Keyboard.begin(); //Start the keyboard slave device
}

void loop() {
  //Put your code here to loop
  
  if(Serial1.available()) { //Check if there is data to read from the keyboard
    
    key = (char)Serial1.read(); //Read the keyboard data into a char.

    //Example munipulation
    Keyboard.press(ctrlKey); //Hold down ctrl key 
    delay(10); //Wait 10 milliseconds to give everything a breather
    Keyboard.print(key); //Send the key from the keyboard
    delay(10); //Wait 10 milliseconds to give everything a breather
    Keyboard.releaseAll(); //Release the ctrl key
  }
  delay(10); //Wait 10 milliseconds to give everything a breather
}

This script reads data from the keyboard and wraps it in a key press.

Clone this wiki locally