Need help, a way to know what key was pressed on the keyboard

Hello, I am trying to make a stay-open application that does things when buttons on the keyboard are pressed, so I need a way to know what key was pressed… Can this be done? for instance, when you push ‘q’ it would beep…ect…

I have never seen a successful AppleScript key logger.