I'm getting an error verifying a sketch directly from Arduino Reference.

The sample sketch from here Keyboard.write() - Arduino Reference
is giving me an error.
#include <Keyboard.h>

int run;
int buttonPin;

void setup()
{
run = 0; //starts stopped
buttonPin = 7; //whatever pin your button is plugged into

pinMode(buttonPin, INPUT_PULLUP);
}

void loop()
{ // make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
Keyboard.begin(65);
}
//code you always run here; you can leave this section blank if you want the entire program to stop and start, or add code here if you want it to always run

//check button press here and if it is pressed then toggle run variable between 0 and 255; REQUIRED!
if(digitalRead(buttonPin) == LOW) //funcitons based off of button pulling input pin LOW
{
if(run == 0)
{
run = 255;
}
else
{
run = 0;
}
}

if(run > 0)
{
//code you only run if button was pressed, stops running when button pressed again, so forth...
}
}

Error Messages: Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Leonardo"

C:\Users\samne\AppData\Local\Temp\arduino_modified_sketch_280712\sketch_apr26b.ino: In function 'void setup()':

sketch_apr26b:8:3: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

That code is NOT exactly like in the example. pinMode() should be called from setup(), not loop(). Ditto for Keyboard.begin().

ALL code must be in a function. You have a lot of code after the end of the loop function.

Yeah sorry i forgot that was the script that I am trying to incorporate the keyboard function into. However it doesn't work when I put in the exact script anyways. It gives the same error message. Thanks for the tips.

do you have the Keyboard library installed?

on the IDE look under Sketch->include Library

It still shows the same message.

ginnisrsdj14:
It still shows the same message.

So we can only assume, since you refuse to provide any answers, that you don't have the Keyboard library installed.

Do you know how to install a library?

The Keyboard library should be installed by default. On the other hand, one never knows with the Windows Store versions.

ginnisrsdj14:
It still shows the same message.

Post your code and please use code tags; see https://forum.arduino.cc/index.php?topic=148850.0