我使用SDL 2.0编写了一个简单的SDL程序。当我想检查鼠标滚轮事件时,我有一点问题。实际上,在版本2.0中,标志SDL_BUTTON_WHEELDOWN和SDL_BUTTON_WHEELUP不再存在。只有标志SDL_MOUSEWHEEL。下面的代码正确检查'WHEELUP'和'WHEELDOWN'事件,但标记相同。
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;
}
}
但我想分别处理'WHEELUP'和'WHEELDOWN'事件。在我的情况下我尝试了其他几个旗帜但没有成功。有人可以帮助我吗?
答案 0 :(得分:8)
你可以通过这种方式捕捉上下事件:
case SDL_MOUSEWHEEL:
if (evenements.wheel.y < 0)
std::cout << "MOUSE : WHEEL DOWN" << std::endl;
else
std::cout << "MOUSE : WHEEL UP" << std::endl;
break;