Keyboard.write does not work

I am attempting to use certain buttons, joysticks, etc with an arduino so that they are each coded to a specific key on the keyboard using the Keyboard.write function. It is important to note that I am not using an actual keyboard. I want to run an emulator off of it. I have everything plugged in correctly but when I go to run the program, an error message shows up and the program does not upload and run. The message goes:

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

I included the library and it still doesn't work. The board I am using is the Elegoo Arduino UNO R3. My line of code is the following:

#include <Keyboard.h>

const int SW_pin = 2;
const int X_pin = A0;
const int Y_pin = A1;

void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);

}

void loop() {

Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(500);
if(X_pin >= 1000)
Keyboard.write('w');

}

I am only using an input for pushing my joystick left for testing but that's not the issue. For whatever reason, the Keyboard.write function does not work even though I have the library installed and included. What should I do? Any assistance would help.

Thanks in advance

Doesn't the compiler give you a clue?

Hint :" I am using is the Elegoo Arduino UNO R3."

This isn't an installation or troubleshooting issue.

The uno does not have native usb.

Keyboard library requires native usb, because it has to be able to tell the microcontroller to appear as a usb hid device, not a serial adapter.

If you want to pretend to be a keyboard, you need to use a board with native usb - leo, micro, due, zero, or one of the other arm boards with native usb.

DrAzzy:
The uno does not have native usb.

Keyboard library requires native usb, because it has to be able to tell the microcontroller to appear as a usb hid device, not a serial adapter.

If you want to pretend to be a keyboard, you need to use a board with native usb - leo, micro, due, zero, or one of the other arm boards with native usb.

Does it matter though? I'm not using any sort of usb keyboard, just the function in the code. I am using other input devices connected straight to the board.

DrAzzy:
The uno does not have native usb.

Keyboard library requires native usb, because it has to be able to tell the microcontroller to appear as a usb hid device, not a serial adapter.

If you want to pretend to be a keyboard, you need to use a board with native usb - leo, micro, due, zero, or one of the other arm boards with native usb.

Thank you for the help regardless. I thought this might've been the issue but I just wanted to make sure that there wasn't some other way I could do it.

For example, I work on a laptop, does it mean that I will have my keyboard, if connecting another keyboard or panel with keys will block my main keyboard?
I want to select with the mouse, type with my keyboard and play with my keyboard or added panel programmed with arduino in this case as I could

Matthew2510:
For example, I work on a laptop, does it mean that I will have my keyboard, if connecting another keyboard or panel with keys will block my main keyboard?
I want to select with the mouse, type with my keyboard and play with my keyboard or added panel programmed with arduino in this case as I could

They all work together in parallel. Try adding a USB keyboard to your laptop and you will see.

Paul