SFML community forums

Help => Window => Topic started by: xzxvvxzx on June 21, 2013, 02:52:38 am

Title: [2.0] Mouse Wheel
Post by: xzxvvxzx on June 21, 2013, 02:52:38 am
Hello, I want to use mouse wheel but when I type:

int mouse_wheel;
if (event.type == sf::Event::MouseWheelMoved)
    mouse_wheel = event.mouseWheel.delta;

mouse_wheel is always 0. How to handle mouse scrolling? I am using Windows 7 and Microsoft Wireless Mobile Mouse 3500.

EDIT: It sometimes change to 1 but I need to move mouse wheel very fast. Is there any way to detect slow mouse wheel movement?
Title: Re: [2.0] Mouse Wheel
Post by: cooldog99 on June 21, 2013, 05:58:12 am
The mouse wheel event changes from -1 -> 1

it doesn't keep a total delta, only the amount of change in that event.

Common practice is to keep a global(doesn't have to be global, just outside the while loop) variable of mouse delta.

see below:

pseudo code:

Code: [Select]
int main(){
     int mouseDelta = 0;

     while loop{
            sf::event newEvent;
                   if (newEvent.type == sf::Event::MouseWheelMoved)
                         mouseDelta += newEvent.mouseWheel.delta;

      return 0;

Here is the official SFML 2 tutorial topic that may help.

also, next time, try to post complete minimal code, so we can diagnose errors better. :)
Hope this helps.