Pressing Keys and Setting Variables

Hi! I am trying to make a neat and tidy code. By doing this, I want to set a variable to true when a key is pressed and false when it is released. Then, on frames I want affected, I want it to constantly check these variables and perform an action if is were to be set to true.

About that last part, would I have to constantly loop the frame so it keeps checking the variables?

Thanks.