There are quite a few ways to access key and button presses via code. How you do this depends on whether you have the key specified as an axis in the Input Manager and whether you want the key to register once or continuously. I'll discuss a few in this text, but you can find a full list of the functions at https://docs.unity3d.com/ScriptReference/Input.html.
A script named KeyPresses is attached to the Main Camera in Text example scene of Chapter4, The Event System and Programming for UI, and contains all the code demonstrated in this section if you'd like to play around with key presses.