It compiles OK for me if I set the board to be a Leonardo
Here is the code laid out slightly differently but fundamentally unchanged
#include <Keyboard.h>
void setup()
{
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
Keyboard.begin();
}
void loop()
{
//if the button on pin 2 is pressed
if (digitalRead(2) == LOW)
{
//Send the message
Keyboard.print("Hello!");
delay(1500);
}
//if the button on pin 3 is pressed
if (digitalRead(3) == LOW)
{
//Send the message
Keyboard.print("World!");
delay(1500);
}
}
Try copy/pasting it into an empty IDE window and compiling it