4

I keep getting this error message:

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

... when I have already included Keyboard.h.

#include <Keyboard.h>

void setup() {
  pinMode(3,INPUT_PULLUP); 
  pinMode(4,INPUT_PULLUP);

 Serial.begin(9600);    //begin seral comms for debugging
}

void loop() {
  Keyboard.begin();
  if (digitalRead(3) == 0) //if button 3 is pushed
   {
Keyboard.write('z');
delay(200);
}
   else if (digitalRead(4) == 0) //if button 3 is pushed
{
  Keyboard.write('x');
  delay(200);
}
  Keyboard.end();
}

Keyboard.h is already included as a default library in Arduino so I'm not sure what's wrong

2
  • 1
    Which Arduino do you have? Please tag your question with that information. – Nick Gammon Nov 7 '18 at 5:46
  • Please update your question, stating which processor and/or board you are using. – Greenonline Nov 7 '18 at 7:06
4

If you have Arduino/Genuino Uno selected as your board in the Tools ► Board ► menu, then you get the error. If you select Arduino Leonardo it compiles correctly.

From Can't seem to be able use Keyboard.h library, this post states:

Keyboard.h (and Mouse.h) only works on devices that use the ATmega32u4 processor, like the Leonardo or Micro. See: https://www.arduino.cc/en/Reference/MouseKeyboard

This solution might help though

I had the same problem using Flora

This worked for me:

  1. Tools > Boards > Boards Manager
  2. Install TeeOnArdu (Then select that board from Boards Manager)
  3. Tools > USB Type > Serial, Keyboard, Mouse < Joypad
  4. Upload and run code again (might need to restart IDE)
2
  • Great... btw, what Arduino board do you have? – Greenonline Nov 9 '18 at 2:05
  • was using a pro micro, it is detected as an arduino leonardo same chip i guess – chin hui Nov 9 '18 at 4:12

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