Keyboard library not working

I'm currently trying to make a keyboard with four arrow keys and an enter key. I am using Arduinos keyboard library Version 1.0.6 and an Arduino UNO R3 for this.
When I compile my code I get some errors and I couldn't figure out how to get it to work. The other posts on this subject didn't help me either.

Here's the code (I cut out the else ifs for the other four buttons in the loop function):

#include <Keyboard.h>

Keyboard kb;

void setup() {
  for(int i = 2; i < 7; i++) {
      pinMode(i, INPUT_PULLUP);
    }
  kb.begin();
}

void loop() {
  if(digitalRead(2) == LOW) {
      kb.press(KEY_LEFT_ARROW);
      delay(250);
      kb.release();
    }
}

When I try to compile this code I get these errors:

In file included from /home/user/Dokumente/Arduino/Sketches2/sketch_Keyboard/sketch_Keyboard.ino:1:0:
/home/user/Arduino/libraries/Keyboard/src/Keyboard.h:29:2: warning: #warning "Using legacy HID core (non pluggable)" [-Wcpp]
 #warning "Using legacy HID core (non pluggable)"
  ^
sketch_Keyboard:3:1: error: ‘Keyboard’ does not name a type
 Keyboard kb;
 ^
/home/user/Dokumente/Arduino/Sketches2/sketch_Keyboard/sketch_Keyboard.ino: In function ‘void setup()’:
sketch_Keyboard:9:3: error: ‘kb’ was not declared in this scope
   kb.begin();
   ^
/home/user/Dokumente/Arduino/Sketches2/sketch_Keyboard/sketch_Keyboard.ino: In function ‘void loop()’:
sketch_Keyboard:14:7: error: ‘kb’ was not declared in this scope
       kb.press(KEY_LEFT_ARROW);
       ^
sketch_Keyboard:14:16: error: ‘KEY_LEFT_ARROW’ was not declared in this scope
       kb.press(KEY_LEFT_ARROW);
                ^
//I left out the errors for the rest of the buttons here
exit status 1
‘Keyboard’ does not name a type

When I change #include <Keyboard.h> to #include <HID.h> the first error goes away but everything else stays.

Thanks in advance for any help or suggestions.

From the Keyboard library reference page:


The Uno R3 is not on that list.

Didn't notice that, thanks! :sweat_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.