Getting mouse wheel states

this works

while( SDL_PollEvent( &event ) )
switch( event.type )
{
case SDL_MOUSEBUTTONDOWN:
if ( event.button.button == SDL_BUTTON_WHEELUP )
{
// works
}

but this doesnt

Uint8 button = SDL_GetMouseState( &x, &y );
if ( button & SDL_BUTTON(SDL_BUTTON_WHEELUP) )
{
// doesnt get called
}
but it works for mouse button left,right + middle

i assume im using it right (arent i?) if not how should it be used.

ta zed___________________________________________________________
Win a BlackBerry device from O2 with Yahoo!. Enter now. http://www.yahoo.co.uk/blackberry

zed zeek wrote:

but it works for mouse button left,right + middle
i assume im using it right (arent i?) if not how should it be used.

From the code, it looks like you’re trying to find out if the mouse
wheel is being ‘held down’ in its ‘up’ state, which doesn’t make too
much sense on my end – perhaps you’re trying to get something else, but
if so, it wasn’t clear from the what exactly you’re trying to get. Can
you explain what you’re trying to do?

Mouse wheel movements are never in a ‘held down’ state – the operating
system, mouse, and/or driver is just sending a ‘down’ event (I assume
they tend to send an immediate ‘up’ event too, but I didn’t verify it)
every time the wheel has moved a significant amount.

Come to think of it, the only way I can think of to really ‘hold down’ a
mouse wheel movement for any significant amount of time would be to take
a Dremel Tool to it.

  • Silicon

this works

while( SDL_PollEvent( &event ) )
switch( event.type )
{
case SDL_MOUSEBUTTONDOWN:
if ( event.button.button == SDL_BUTTON_WHEELUP )
{
// works
}

but this doesnt

Uint8 button = SDL_GetMouseState( &x, &y );
if ( button & SDL_BUTTON(SDL_BUTTON_WHEELUP) )
{
// doesnt get called
}
but it works for mouse button left,right + middle

i assume im using it right (arent i?) if not how should it be used.

ta zed

AFAIK mouse wheels send events, ie.


while ( (SDL_PollEvent ( &event )) && (maxEventCount))
{
if (event.type == SDL_KEYDOWN)
{
if ((event.key.keysym.unicode ) == 0)
actKeys[event.key.keysym.sym] = 1;
else
actKeys[event.key.keysym.unicode] = 1;
}
else if (event.type == SDL_KEYUP)
{
actKeys[event.key.keysym.sym] = 0;
}
// it’s special occasion - “Wheel up” is a momentary event, not a
state.
// so we should use SDL_PollEvent() instead of SDL_GetMouseState().
else if (event.type == SDL_MOUSEBUTTONDOWN )
{
if (event.button.button == SDL_BUTTON_WHEELUP)
mouseWheelUp = true;
else if (event.button.button == SDL_BUTTON_WHEELDOWN)
mouseWheelDown = true;
}

Well, at least it works for me.

Koshmaar

Hello zed,

Mouse wheels only seem to be event driven. Presumably this is because
on most OS’s this is how mouse wheels are handled.

It’d be good to add a function to SDL that returns mouse wheel deltas,
like SDL_GetRelativeMouseState() but for the wheel. Or, extend the
SDL_GetRelativeMouseState() function to include the wheel as the
Z-axis (this is how DirectInput represents it, i belive)–
Best regards,
Peter mailto:@Peter_Mulholland

John Silicon wrote:

From the code, it looks like you’re trying to find out if the mouse
wheel is being ‘held down’ in its ‘up’ state, which doesn’t make too
much sense on my end

true but that seems to be how sdl does it, it considers wheelup,down to be button presses + not
like say the mouse movement with number of units on x axis/y axis. then again with scrooling my
mouse wheel it does seem to be very distinct, ie u can feel it clicking when u move itmore than a
certain amount. i assume all mouse wheels are the same

cheers koohmaar ive implented something similar

ie
grab the state as an event

case SDL_MOUSEBUTTONDOWN:
if ( event.button.button == SDL_BUTTON_WHEELUP )
g_OS.input.event_mousewheelup = true;

  • then later on

Uint8 button = SDL_GetMouseState( &x, &y ); // left/right/middle buttons
event_mousewheelup // also up+down wheel states

peter, whilst SDL_GetRelativeMouseState() sounds ok im not 100% sure many mice do it this way, as
i wrote above with my mouse at least u need to scrool quite a bit before the scroll message is
generated___________________________________________________________
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com