O'Reilly logo

openFrameworks Essentials by Denis Perevalov, Igor Tatarnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required