Simulating keyboard keypresses for a foot controlled keyboard extension.

Here's the code that I found relevant for my project. When I verify this I get the error "'KEY_LEFT_CTRL' was not declared in this scope". I want to start testing out the code on my new arduino feather. Thanks for the help.

// use this option for OSX:
// char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux:
char ctrlKey = KEY_LEFT_CTRL;  

void setup() {
  // make pin 2 an input and turn on the 
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  // initialize control over the keyboard:
  Keyboard.begin();
}

void loop() {
  while (digitalRead(2) == HIGH) {
    // do nothing until pin 2 goes low
    delay(500);
  }
  delay(1000);
  // new document:
  Keyboard.press(ctrlKey);
  Keyboard.press('n');
  delay(100);
  Keyboard.releaseAll();
  // wait for new window to open:
  delay(1000);
}

You're probably missing an include at the beginning of your code.

#include <somefile.h>

// other code here
...
...

where somefile.h is the file that contains the missing definitions; possibly Keyboard.h

Please edit your post and change the quote tags to code tags so your post looks like

your code here

Easier to read and easier to copy.

Question: which board are you using?

I added

#include <Keyboard.h>

Still get the same error.

I appreciate your response and fixed the formatting on my code as per your suggestion.

Thanks for editing the opening post..

Your compiles (after adding the include) if you select the correct board in the tools menu. I don't have boards that support HID but just picked a Leonardo and it compiled. Hence the question in my previous post which board you are using.

IDE 1.6.6 in case it is relevant.

Forgot that, I'm using the Feather. I have it set as an arduino uno.

And yeah, I'm using ide 1.6.11

Solved now? I only have Unos and it indeed did not compile :wink:

Still unsolved. here's the code I'm working with currently:

#include <Keyboard.h>
char ctrlKey = KEY_LEFT_CTRL;  

void setup() {
  // make pin 2 an input and turn on the 
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  // initialize control over the keyboard:
  Keyboard.begin();
}

void loop() {
  while (digitalRead(2) == HIGH) {
    // do nothing until pin 2 goes low
    delay(500);
  }
  delay(1000);
  // new document:
  Keyboard.press(ctrlKey);
  Keyboard.press('n');
  delay(100);
  Keyboard.releaseAll();
  // wait for new window to open:
  delay(1000);
}

No experience with Feathers; only thing I can say is to make sure that you pick the correct board from the toold menu (and as said, compiling for Uno will not work).

Thanks so much for your patience. After googling around a bit more, I found this:

I thought the board was covered under the uno, but I needed to install the feather. Solved!