Detecting key

How do I detect key pressed, so first I have to press key then release it, wich causes an action?

Pseudocode:

If the key is pressed - Do = 1 variable keypress

If the key is NOT pressed - Do action Variable keypress = 1 -Variable keypress = 0

you are genios! Im so thankfully for you! This will make my 2D RPG game a LOT easier to do!