Detect Keypress

Im trying to write code to detect key press and do something.
Pseudocode:

if spacebar pressed:
do (action)

I have tried KeyboardController but

#include <KeyboardController.h>

does not register as a library. I’m using 1.8.10

Im trying to write code to detect key press and do something.

Where is that key? If on a keyboard, how is that keyboard connected to the Arduino? A standard Arduino doesn't have a keyboard attached. Provide much more information about the hardware you're using!

Also, what have you done to install theKeyboardController library? Where is it? Please provide a link to the library also.

I am using my computer keyboard with my arduino attached to it with a USB cable.
I was looking for a download to the keyboard controller library but I could only find the Keyboard library so I tried importing it thinking it would be default.

I am using my computer keyboard with my arduino attached to it with a USB cable.

You cannot connect an USB keyboard to an Arduino UNO (that's the model we expect you to have if you don't specify it)!

I was looking for a download to the keyboard controller library but I could only find the Keyboard library so I tried importing it thinking it would be default.

Does that mean you just took any random library name and put that into an #include statement and hoped that it may load the correct library? That's rather brave but it's not the way programming works, unfortunately.

pylon:
Does that mean you just took any random library name and put that into an #include statement and hoped that it may load the correct library? That's rather brave but it's not the way programming works, unfortunately.

No. I had seen lots of other posts using the KeyboardController library so i assumed it was a default library or at least a downloadable one so i first tried to use it and then tried to download/install it but i could not find it.

There's a post that talks about connecting a PS2 keyboard (they plugged in to the old green and purple ports on older PC's). You can use that if your keyboard has a PS2 connector on it.

SNEAKY SECRET: You can also use a USB keyboard, you just need to use a USB to PS2 converter. PS2 ports are actually the same as USB ports, but they are round and have 2 dummy pins.

What exactly are you trying to accomplish? Why a keyboard into an Arduino, and not just a button?

No. I had seen lots of other posts using the KeyboardController library so i assumed it was a default library or at least a downloadable one so i first tried to use it and then tried to download/install it but i could not find it.

The only web pages I find that use a KeyboardController library are about using a USB Host Shield to connect a USB keyboard. Do you use such a hardware?

But I agree with KingDubDub, explain in detail what you're trying to achieve and not how you think it should be done. Maybe we can give you some hints.