HID library "does not name a type"

I just got my Arduino Uno yesterday and I’m trying to use the HID library to get the computer to recognize the board as a joystick (I’m wanting to run an experiment within a flight simulator). But I cannot get the thing to compile without getting a “‘HIDSubDescriptor’ does not name a type” error, as well as “HID is not declared in scope”. I do have the necessary includes, but for some reason, it just refuses to compile.

When the IDE is set to “Arduino Leonardo”, it doesn’t give any errors, but it also never finishes uploading.

#include <HID.h>
...
static const hidDescriptor[] PROGMEM = { ... };
...
void setup()
{
	...
	static HIDSubDescriptor node(hidDescriptor, sizeof(hidDescriptor)); // does not name a type
	HID().AppendDescriptor(&node);  // not declared in scope
	...
}

IDE Version: 1.8.8
Board: Arduino/Genuino Uno

How can I resolve this error?

I tried moving the library to the “[Arduino Install Path]/libraries” folder, the “[User]/Documents/Arduino/Libraries” folder, and putting the code into the project folder itself. Nothing worked.

EDIT: Corrected hidDescriptor definition to match the actual code.
NOTE: None of the searches were helpful.

When the IDE is set to "Arduino Leonardo", it doesn't give any errors, but it also never finishes uploading.

If you have compiled code for the Leonardo, and are try to upload it to a Uno, do you REALLY expect that to work?

The only person you have to blame for buying the wrong Arduino is you.

How rude! And unhelpful.

TChapman500: How rude! And unhelpful.

I could have commented on your stupidity for trying to compile code for one board type, and upload it to a different board. But, I didn't.

You can NOT use the HID library on a board that doesn't have the necessary hardware to support it, which the Uno does not have.

In that case, time for a workaround.

If you’re really set on a workaround to use the Uno: On a genuine Arduino Uno or a clone that also uses the ATmega16U2 USB to TTL serial chip (it won’t work on a board with the CH340). It is possible to achieve HID functionality by uploading special firmware to the ATmega16U2. The reason is that, even though the primary ATmega328P microcontroller on the Uno doesn’t support HID, the ATmega16U2 does. There is a project that is intended to make this a bit easier:

Note that this is a very advanced project that has the possibility to “brick” your Uno if you aren’t successful. I would very much recommend just buying an Arduino board that is meant for your intended usage. However, if you’re up for a challenge, you might have fun exploring the possibilities of the Uno’s ATmega16U2.