2

The IDE tells me the included library isn't? I tried restarting the IDE and my computer but it doesn't work. The other libraries work fine it's only with Keyboard that it fails.

My code:

#include <Keyboard.h>

int buttonState = 0;

void setup() {
  pinMode(2, INPUT);
  pinMode(13, OUTPUT);

  Keyboard.begin();
}

void loop() {
  buttonState = digitalRead(2);
  if (buttonState == HIGH) {
    digitalWrite(13, HIGH);
    Keyboard.press('A');
  } else {
    digitalWrite(13, LOW);
    Keyboard.releaseAll();
  }
}

Error log:

Arduino: 1.6.8 (Windows 10), Board: "Arduino/Genuino Uno"

D:\Documents\Test\Test.ino: In function 'void setup()':

Test:9: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
   Keyboard.begin();

   ^

D:\Documents\Test\Test.ino: In function 'void loop()':

Test:16: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
 Keyboard.press('A');

 ^

Test:19: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
     Keyboard.releaseAll();

     ^

exit status 1
'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

1 Answer 1

4

I see you are using an Arduino Uno.

An Arduino Uno cannot act as a USB keyboard - therefore the Keyboard library doesn't exist for it (the file Keyboard.h is seen as being empty).

You can only use Keyboard.h on boards where using Keyboard.h makes any kind of sense, such as the Leonardo.

4
  • Ok thanks. Should I delete the question because that seems obvious now?
    – Nicolas
    May 12, 2016 at 1:21
  • @Atom: Did you find any other questions asking same? May 12, 2016 at 1:21
  • @IgnacioVazquez-Abrams If he'd looked I'm sure he would have done. I know for a fact that I have answered the same question before.
    – Majenko
    May 12, 2016 at 1:22
  • No but I think they say it here arduino.cc/en/Reference/MouseKeyboard, it just isnt clear
    – Nicolas
    May 12, 2016 at 1:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.