Events are the basis for writing interactive applications in MacroLibX.
So it’s essential that you understand this chapter thoroughly, as it will come in handy in your future graphics projects.
All MacroLibX hooks are nothing more than a function that is called whenever an event is triggered.
The base of all MacroLibX events is mlx_on_event. This function is used to manage all of the events, from keyboard to window events.
It’s is used to attach a function hook to a specific event like keyboard down, or mouse wheel event. That hook will be called every time
this specific event is triggerd.
⌨️ Keyboard
To get keyboard events, we need to use MLX_KEYDOWN or MLX_KEYUP when calling mlx_on_event to set the correct hook.
Here’s how we could do it :
🖱️ Mouse
Same thing that keyboard events, we need to use MLX_MOUSEDOWN, MLX_MOUSEUP or MLX_MOUSEWHEEL when calling mlx_on_event to set the correct hook.
Here’s how we could do it :
🖥️ Window events
The last type of events we can handle are window events (window moved, window maximized, window focused, window closed, … ).