Problem with #include <Keyboard.h>

Hi,

I’m trying to make a Keyboard and Mouse emulator with Arduino Pro Micro, I did a year ago but now I’m trying to make it again it’s not working I’m trying to upload this code

#define OSX 0
#define WINDOWS 1
#define UBUNTU 2
// change this to match your platform:
int platform = OSX;

#include <Keyboard.h>

// use this option for OSX.
// Comment it out if using Windows or Linux:
char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux.
// leave commented out if using OSX:
//  char ctrlKey = KEY_LEFT_CTRL;

void setup() {
  pinMode(3, INPUT_PULLUP);
  Keyboard.begin();
  
   if(digitalRead(3)==LOW){
    //Send the message
    Keyboard.print("Hello!");
  }
}

void loop() {
 
}

But it’s giving me this error

Arduino: 1.6.10 (Mac OS X), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

ShellKeyboard_:12: error: 'KEY_LEFT_GUI' was not declared in this scope
char ctrlKey = KEY_LEFT_GUI;
               ^
/Users/ahmedibrahim/Documents/Arduino/ShellKeyboard_/ShellKeyboard_.ino: In function 'void setup()':
ShellKeyboard_:19: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
  Keyboard.begin();
  ^
Multiple libraries were found for "Keyboard.h"
Used: /Applications/Arduino.app/Contents/Java/libraries/Keyboard
Not used: /Users/ahmedibrahim/Documents/Arduino/libraries/Keyboard-master
exit status 1
'KEY_LEFT_GUI' was not declared in this scope
Invalid library found in /Users/ahmedibrahim/Documents/Arduino/libraries/SparkFunBoard_Addons_Jan_16: /Users/ahmedibrahim/Documents/Arduino/libraries/SparkFunBoard_Addons_Jan_16

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

Please help me

ahmedmarwan2205:

Arduino: 1.6.10 (Mac OS X), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

You need to select Tools > Board > Arduino/Genuino Micro.

pert:
You need to select Tools > Board > Arduino/Genuino Micro.

I already have 1.6.10

Read what I wrote again.

Hello

I have the same problem with a Elegoo Nano card (ATmega328P and CH340 chip).

After compiling it says:

Arduino : 1.8.9 (Windows 10), Carte : “Arduino Nano, ATmega328P”

Plusieurs bibliothèque trouvées pour “Keyboard.h”
Utilisé : C:\Users\marcu\Documents\Arduino\libraries\Keyboard
Non utilisé : C:\Users\marcu\Documents\Arduino\libraries\Keyboard-master
Non utilisé : D:\progs\Arduino\libraries\Keyboard
Utilisation de la bibliothèque Keyboard version 1.0.2 dans le dossier: C:\Users\marcu\Documents\Arduino\libraries\Keyboard
Utilisation de la bibliothèque HID version 1.0 dans le dossier: D:\progs\Arduino\hardware\arduino\avr\libraries\HID
exit status 1
‘Keyboard’ introuvable. Est-ce que votre croquis inclut la ligne ‘#include <Keyboard.h>’ ?

============

it found keyboard librairies folder… but no #include <Keyboard.h>’ ?

The Keyboard library can only be used on the native USB boards like the Micro, Leonardo, and MKR. You cannot use the Keyboard library with your Nano.

Thanks for your reply. You are right, the one I have is the 328P
Leonardo seems discontinued

All Pro micro I see have ATMEGA32U4 Chip... it seems I need ATMega43u4

Will the Arduino A000053 (Micro) do the job?

Eternytime:
All Pro micro I see have ATMEGA32U4 Chip... it seems I need ATMega43u4

Wrong. The ATmega32U4 boards work fine with the Keyboard library. There is no such thing as a ATMega43u4.

Eternytime:
Will the Arduino A000053 (Micro) do the job?

Yes, it will work great.