If I had to guess you are attempting to use this code outside a function to run it from.
So for example:
Func _proccess(Delta): #This here is a function that runs at every frame of your game
If Input.is_action_pressed(): #if key is pressed. Do thang.
Hopefully this helps. ^-^