Library not working

Hi Im trying to get this to work but i keep getting the error message : 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

Although I have included it can someone help me thanks

#include <Keyboard.h>
void setup()
{
    pinMode(2,INPUT);
    digitalWrite(2,HIGH);
    digitalWrite(2,LOW);

    Keyboard.begin();

    while(digitalRead(2))
}

void loop()
{
    Keyboard.println("HELLO WORLD");
    delay(1000);
    Keyboard.println("I AM ALIVE");
    delay(1000);
    Keyboard.write(48); //character 0
    delay(2500);
    Keyboard.press(KEY_BACKSPACE);
    delay(500);
    Keyboard.println("HELLO WORLD");
    delay(1000);
    Keyboard.println("I AM ALIVE");
    delay(1000);
    Keyboard.println("HELLO WORLD");
    delay(1000);
    Keyboard.println("I AM ALIVE");
    delay(1000);
    Keyboard.releaseAll();
    
}

What type of Arduino are you using? You've read this and seen which board the keyboard library will work for right?

What is the actual error message from the compiler? It didn't paraphrase.

I'm Using a Leonardo but it won't even compile here is the full error msg:

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

In file included from C:\Users\etwat\Downloads\sketch_nov12a\sketch_nov12a.ino:1:0:

C:\Program Files (x86)\Arduino\libraries\Keyboard\src/Keyboard.h:29:2: warning: #warning "Using legacy HID core (non pluggable)" [-Wcpp]

#warning "Using legacy HID core (non pluggable)"

^

C:\Users\etwat\Downloads\sketch_nov12a\sketch_nov12a.ino: In function 'void setup()':

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

^

sketch_nov12a:11: error: expected primary-expression before '}' token

}

^

C:\Users\etwat\Downloads\sketch_nov12a\sketch_nov12a.ino: In function 'void loop()':

sketch_nov12a:15: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.println("HELLO WORLD");

^

sketch_nov12a:21: error: 'KEY_BACKSPACE' was not declared in this scope

Keyboard.press(KEY_BACKSPACE);

^

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

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Alright fix the easy one first:

while(digitalRead(2))

Need a set of braces behind that, even if you mean it to be an empty loop. Or at least a semicolon.

Thanks did that the main thing I'm trying to fix is the Keyboard not found

Ew9333:
I'm Using a Leonardo

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

Do you see the problem? If you're using a Leonardo you need to select Tools > Board > Arduino Leonardo.

XD should have known better but now I just get an error compiling for board Leonardo and Leonardo ETH

Ew9333:
XD should have known better but now I just get an error compiling for board Leonardo and Leonardo ETH

Did you notice how with that last one, once you posted the actual error message someone was able to tell what it meant? Can you imagine how much more useful that is than

I just get an error compiling for board Leonardo and Leonardo ETH

I also get the same error the the normal Leonardo Board

Arduino: 1.8.5 (Windows 10), Board: "Arduino Leonardo ETH"

Build options changed, rebuilding all
libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::Keyboard_()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::Keyboard_()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::begin()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::end()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::sendReport(KeyReport*)'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::press(unsigned char)'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `_asciimap'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::release(unsigned char)'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::write(unsigned char)'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::releaseAll()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Leonardo ETH.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please use code tags when you post error/warning messages, just as you did with your code. This will avoid all those frowny faces you see in your last reply.

Try restarting the Arduino IDE and then compiling again. It looks like it somehow ended up with two copies of the Keyboard library in the temporary build folder due to some glitch in the build process unrelated to anything in your code or settings.

Still getting the same error >:( Should I try and reinstall the library? Would that help?

Arduino: 1.8.5 (Windows 10), Board: "Arduino Leonardo"

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::Keyboard_()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::Keyboard_()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::begin()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::end()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::sendReport(KeyReport*)'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::press(unsigned char)'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `_asciimap'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::release(unsigned char)'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::write(unsigned char)'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Keyboard\Keyboard.cpp.o (symbol from plugin): In function `Keyboard_::Keyboard_()':

(.text+0x0): multiple definition of `Keyboard_::releaseAll()'

libraries\Keyboard\Keyboard (2).cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Leonardo.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please do this:

  • File > Preferences > Show verbose output during: > compilation (check) > OK
  • Sketch > Verfiy/Compile
  • After the compilation fails copy and paste the output here, just as you did in your last reply.

I can get more information to help you from the verbose output.

It exceeds 9000 characters cant post the error. RIP

sketch_nov13b.ino (641 Bytes)

Save it in a text file and attach it.

Here you go sorry I didn't think of it

Error Code for Keyboard Program.txt (37.8 KB)

For some reason there is a duplicate source file in your Keyboard library, which is the cause of the error. You need to delete C:\Program Files (x86)\Arduino\libraries\Keyboard\src\Keyboard (2).cpp. If you see any other files in that location that end in (2) delete them also.

There's nothing wrong with messing around in the libraries but you should keep careful track of what changes you've made so that when you do end up with a strange error like this you have a clue as to the cause "That's right, I created a file named Keyboard (2).cpp and now I'm getting errors about that file, I guess I should try deleting it".

THANK YOU SO MUCH IT WORKED

Is there anything I can give you in return?

Consider at some point contributing to the Arduino community in some way. That could include helping someone out here on the forum, reporting a bug, improving the Arduino Playground, publishing a sketch or library or tutorial you wrote, telling people about Arduino, etc. The main reason the Arduino project has been so successful is that so many people have volunteered some of their time and knowledge. I've benefited greatly from all of that and so I try to give back as my limited free time and skills allow. Even if it's just a very small contribution it really adds up when you have thousands of people all over the world working on a project.

A beginner may be limited in their knowledge but they are the users Arduino was specifically targeted to so their input is especially valuable. This is especially true with the documentation. An experienced user may not need to look at the documentation or when they do they will automatically fill in blanks mentally and may not even notice errors since they're only skimming over content they've seen before. So if you find things that don't make sense or are wrong feel free to report them.

Arduino has just recently made it very easy to propose fixes or improvements to the Language Reference pages. You will see an "Edit this page" button on every one of the Language Reference pages as well as links to information on how to use that feature. I can tell you there is a lot of room for improvement on those pages. If you speak a language other than English there are also translation projects underway, which can be a very good opportunity to easily make a valuable contribution to the project.