Handling keyboard events
The keyboard events are handled by the keyPressed(int key)
and keyReleased(int key)
functions, which are called by openFrameworks when a key is pressed and released respectively. The key
input argument holds the numerical code of the key. Let's implement handling key pressings in our project and use it to add some desirable features: hiding GUI, saving screenshots, and saving/loading presets.
Tip
We consider here only key pressing events. Handling key releasing is implemented in a similar way.
Hiding the GUI
In order to capture the image generated with our project, we need to be able to hide the GUI from the screen. To achieve this, let's define the Boolean variable showGui
, implement its toggling by pressing Z, and use its value to decide whether we should draw gui
on the screen:
- Add the variable definition to the
ofApp
class:bool showGui;
- Next, set up its starting value in
setup()
:showGui = true;
- Now, implement its toggling by inserting the following command...