Looking for Mouse.h and Keyboard.h files

I'm trying to program this keyboard and mouse demo program on a Leonardo:

But my Arduino IDE cannot find the Keyboard.h or the Mouse.h files.

I've searched my hard drive and cannot find them.

I've used the Include Library menu inside the IDE but I cannot find them in there either.

Where can I down load these .h files?

Thanks...

This seems to be an error in the tutorial(s).

The keyboard.h is not neccessary for compilation, just drop it. :wink:

For reference Removing useless includes from examples

If I rem out the include lines, each Mouse and Keyboard line has a red squiggly line under them indicating an error because the object (Mouse. or Keyboard.) can't be found. I'm using Visual Studio Community edition for my Ardunio development.

Here is the code I am trying to learn with.

/*
KeyboardAndMouseControl

Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due.

Hardware:

  • 5 pushbuttons attached to D2, D3, D4, D5, D6

The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.

WARNING: When you use the Mouse.move() command, the Arduino takes
over your mouse! Make sure you have control before you use the mouse commands.

created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe

this code is in the public domain

*/

//#include "Keyboard.h"
//#include "Mouse.h"

// set pin numbers for the five buttons:
const int upButton = 2;
const int downButton = 3;
const int leftButton = 4;
const int rightButton = 5;
const int mouseButton = 6;

void setup() { // initialize the buttons' inputs:
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(leftButton, INPUT);
pinMode(rightButton, INPUT);
pinMode(mouseButton, INPUT);

Serial.begin(9600);
// initialize mouse control:
Mouse.begin();
Keyboard.begin();
}

void loop() {
// use serial input to control the mouse:
if (Serial.available() > 0) {
char inChar = Serial.read();

switch (inChar) {
case 'u':
// move mouse up
Mouse.move(0, -40);
break;
case 'd':
// move mouse down
Mouse.move(0, 40);
break;
case 'l':
// move mouse left
Mouse.move(-40, 0);
break;
case 'r':
// move mouse right
Mouse.move(40, 0);
break;
case 'm':
// perform mouse left click
Mouse.click(MOUSE_LEFT);
break;
}
}

// use the pushbuttons to control the keyboard:
if (digitalRead(upButton) == HIGH) {
Keyboard.write('u');
}
if (digitalRead(downButton) == HIGH) {
Keyboard.write('d');
}
if (digitalRead(leftButton) == HIGH) {
Keyboard.write('l');
}
if (digitalRead(rightButton) == HIGH) {
Keyboard.write('r');
}
if (digitalRead(mouseButton) == HIGH) {
Keyboard.write('m');
}

}

I’m using Visual Studio Community edition for my Ardunio development.

No consolation to you, but the code compiles OK in the Arduino IDE as long as the appropriate target board is selected.

Also, please read the two posts at the top of this Forum by Nick Gammon on the proper way to post source code here using code tags.

Also, I would change the Serial.read() call to:

char inChar = tolower(Serial.read());

That way, if the user does enter a capital letter, your code would still process the letter correctly.

I switched back to the Arduino IDE and kept the include lines remmed out. I also selected the Leonardo board.

It complied ok but I got 3 warnings. I'm puzzled by them because I'm not using these files.

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring.c: In function 'init':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring.c:318:3: warning: #warning Timer 2 not finished (may not be present on this CPU) [-Wcpp]
  #warning Timer 2 not finished (may not be present on this CPU)
   ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring.c:327:3: warning: #warning Timer 2 not finished (may not be present on this CPU) [-Wcpp]
  #warning Timer 2 not finished (may not be present on this CPU)
   ^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\Tone.cpp:212:12: warning: #warning this may not be correct [-Wcpp]
           #warning this may not be correct