# Events management using SDL 2.0

I wrote a simple SDL program using SDL 2.0. I have a little problem when I want to check the mouse wheel events. Actually, in the version 2.0 the flags SDL_BUTTON_WHEELDOWN and SDL_BUTTON_WHEELUP no longer exist. There is just the flags SDL_MOUSEWHEEL. The code below check correctly the' WHEELUP' and 'WHEELDOWN' events but with the same flag.

while(!terminer)
{
while (SDL_PollEvent(&evenements))
{
switch (evenements.type)
{
case SDL_QUIT:
terminer = true;
break;
case SDL_KEYDOWN:
switch (evenements.key.keysym.sym)
{
case SDLK_ESCAPE:
terminer = true;
break;
}
break;
case SDL_MOUSEMOTION:
std::cout << "MOUSE : MOVE" << std::endl;
break;
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
std::cout << "MOUSE : BUTTON DOWN" << std::endl;
break;
case SDL_MOUSEWHEEL:
std::cout << "MOUSE : WHEEL" << std::endl;
break;
}
}


But I would like to handle separately the 'WHEELUP' and 'WHEELDOWN' events. I tried several others flags in my condition but without success. Does anyone can help me, please ?

Movements to the left generate negative x values and to the right generate positive x values. Movements down (scroll backward) generate negative y values and up (scroll forward) generate positive y values.

So in your case, you could modify the code as such:

case SDL_MOUSEWHEEL:
if(evenements.x < 0)
{
std::cout << "MOUSE : WHEEL LEFT" << std::endl;
}
else if(evenements.x > 0)
{
std::cout << "MOUSE : WHEEL RIGHT" << std::endl;
}
if(evenements.y < 0)
{
std::cout << "MOUSE : WHEEL DOWN" << std::endl;
}
else if(evenements.y > 0)
{
std::cout << "MOUSE : WHEEL UP" << std::endl;
}
break;

• Hello. I didn't talk about the mouse motion (when you move the mouse with the hand in all the direction represented by the SDL_MOUSEMOTION flag) but the wheel of the mouse (the wheel between the two button represented by the flag SDL_MOUSEWHEEL). I don't know how to separate the 'UP' event and the 'DOWN' event. Actually both are represented by SDL_MOUSEWHEEL flag. – user1364743 Mar 8 '14 at 19:23
• Did you read the link? This is valid for the mouse wheel. – user39686 Mar 8 '14 at 19:26
• Ok sorry. As you say, in my example the 'wheel down' event is right for the condition if evenements.wheel.y < 0 and 'wheel down' is right if the condition evenements.wheel.y > 0 is respected. Thank you very much for your answer! Bye. – user1364743 Mar 8 '14 at 19:40