The code you suggests works when using the correct methods and placing it in
var pressed = false
pressed = Input.is_key_pressed(KEY_A)
elif not pressed:
However, this is usually done using Input event handlers and Input mapping.
The Godot "Your First Game" tutorial shows how to do this properly:
Godot 3.1 Your First Game