Key Pressed/Key Released Basics

Looking to make a program that runs a specific function only while the key is pressed. I currently have a code using the key pressed function. When I press the key, it turns the function on, and when I release the key, the function is still on and the function stays on until I press the key again. I only want the function to be turned on momentarily while the key is being pressed. Do I need to use a combination of key pressed/key released functions and if so how would I go about that? Thanks

Yes, you can use a bool variable to register this.

Something like:
set to true on keyPress and to false when keyRelease.
Then check the bool state somewhere in update/draw.

Notice that the toggle manages a state active (key mod is pressed or not), not a trig/bang on a precise moment. (key is just pressed now)

1 Like