 As an example, let's say the user clicks the X button, how do we handle that event? Well, the way that we would handle that event is we would say if e.type is equal to sdl quit, we are going to set running to false. And this is a very simple example. So the reason I'm setting running to false is because I have this loop here that just keeps the program running. If we see that the event type that happened was the quit, so the user clicked the X button under window, we're going to set running to false. So it's just going to fall through. It's going to just return from this function, the main function, and the program exits. Simple enough. Let's see how that works. Okay, so we have this little rack. I'm going to show how to handle keys with this rectal later. But for now, we are just going to click the X button. And as you can see, we exited the program. The reason we exit the program is because we pulled the event. The event type was sdl quit because it was sdl quit. We set running to false. And because of that, the program exits because we just stop the while loop. Okay, so let's say we want to handle a key event. So if we say if e dot type is equal to sdl key down, so let's say we click a key, what do what do we do here? Well, one thing we can do is we can say see out key was pressed. And when we execute this, and we click something, as you can see, the terminal is echoing out key was pressed. But here's the problem. We want to know which key was pressed in particular, right? So you don't really care if a key is pressed, we want to know what key was pressed in detail. And to get the exact key that was pressed, we actually have to check every single one. So I think most people recommend using a switch statement for this. So the way you do that is you just say switch, and then you're going to switch on this variable e dot key dot key sim dot sim. And you just give it a case, then if the case matches, you're going to basically just echo out this key was pressed. So let's say case case sdl k, right? So if the right key is pressed, what are we going to do? We are going to do see out rate key was pressed. Okay, so let's see if that worked. And we're going to click the right key. And when we click the right key, we see that the terminal rates rate key was pressed. That's good. Okay, so what if we are interested in what happens when the right key is released? So we can basically do the same thing. You can say if actually, I think I should make these if else statements. Okay, we're going to say e dot type is equal to stl stl key up. So when the key is released, what we're going to do, this is basically going to be a mirror of the previous except in reverse, let's say switch e dot key dot key sim dot sim. And here we are going to check the case case, stl k, right? So if the right key was pressed, we are going to see out rate key was released. Okay, let's execute this again. Then we are going to click the right key. As you can see, key was pressed, released, pressed, released. Okay, good. So what can we do with this? Why is this good? Actually, I think you should also add break. I mean, I don't have any other key, I have no other cases here, but I think we should also add a break statement. Break. Okay, so what we're going to do here is we have this rect, this rect is at position 1010 and its size is 250 250. Now what we can do is we can say, okay, so when the rate key is pressed, we are going to increase the x position of this rect by 50. So dot x plus equals to 50. And when it's released, I guess nothing, because I don't know, we're not going to make it go backwards. But okay, so we're going to get this. I'm going to say, if this rectangle, if the right key is pressed, we're going to increase this rectangle by 50. And let's execute this and see what happens. So we're going to click the right button. And as you can see, the position gets increased by 50 every time we click. Okay, that's good. What else you can do is you can check for a mouse motion event. So you can say else if eta type is equal to stl mouse motion. So if the mouse is moved, the mouse position. And we get the mouse position by essentially getting the stl. You run the function called stl mouse get state, or stl get mouse state. And what you do is you pass in two integers, and those integers will be populated with the state of the mouse x and y position. So to do that, we do stl get mouse state. Then we are going to pass in the address of two integers. Because I don't want to define two integers, I'm just going to use the rects x and y positions. So we can say r dot x or dot y. And these have to be addresses because it's going to populate those. And then we're going to close that right. Okay. So we have this window. And as you can see, when I move the mouse, the mouse movement is an event. And because it's an event, it's going to set the position of the x and y of this rectangle to the position of the mouse. Let's close that. Yeah, so that's pretty much all you really need to know with the event system. The event system is pretty simple. What it does is it just gets all of the events that happen. Then you can use this while loop to basically go through every event and then check which event it is. And if it's the event that you want to handle, you can handle it. Otherwise, it's just going to, you're just going to let it go. So here in this example, we're handling the stl quit, stl key down, stl key up, and stl mouse motion events. Otherwise, we don't care. We don't care what happens. Just to show you again, as you can see, when the mouse moves, I set the position of the rectangle to be the position of the mouse. But if I move, if I click the right key, the position is no longer the position of the mouse. But if I move the mouse again, the mouse gets set to the position, or the rectangle gets set to the position of the mouse. That is essentially how the event system works in stl. Thanks for watching and I guess I'll see you in the next video.