The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
[2.0]-Clear Mouse Button Down Events At App Start?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
[2.0]-Clear Mouse Button Down Events At App Start?

Hi,

I have a weird issue with SDL 2.0.3 on Microsoft Windows 8.1 Pro 64Bit.
When the SDL2 game first starts it registers a mouse button down event which I want to fix.
How can I clear all mouse button down events at application start in SDL2?

Thanks!
[2.0]-Clear Mouse Button Down Events At App Start?
MrOzBarry


Joined: 26 Jun 2010
Posts: 620
You could just run a loop like:

SDL_Event discard;
while (SDL_PollEvent(&discard)) {}


That will clear the event buffer, and stop once the first few events are fired.  You shouldn't, however, be getting a mouse down unless you're clicking.  Can you try starting your app from the command line; the app might be registering a click from double clicking the executable or something odd like that.  If the command line fixes that, then at least you know where the click is coming from.


-Alex


On Mon, Mar 2, 2015 at 11:06 AM, JeZ-l-Lee wrote:
Quote:
[2.0]-Clear Mouse Button Down Events At App Start?

Hi,

I have a weird issue with SDL 2.0.3 on Microsoft Windows 8.1 Pro 64Bit.
When the SDL2 game first starts it registers a mouse button down event which I want to fix.
How can I clear all mouse button down events at application start in SDL2?

Thanks!



JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

[2.0]-Clear Mouse Button Down Events At App Start?
MrOzBarry


Joined: 26 Jun 2010
Posts: 620
I should mention that loop should be placed before your main application loop.

On Mon, Mar 2, 2015 at 11:23 AM, Alex Barry wrote:
Quote:
You could just run a loop like:

SDL_Event discard;
while (SDL_PollEvent(&discard)) {}


That will clear the event buffer, and stop once the first few events are fired.  You shouldn't, however, be getting a mouse down unless you're clicking.  Can you try starting your app from the command line; the app might be registering a click from double clicking the executable or something odd like that.  If the command line fixes that, then at least you know where the click is coming from.


-Alex


On Mon, Mar 2, 2015 at 11:06 AM, JeZ-l-Lee wrote:


Quote:
[2.0]-Clear Mouse Button Down Events At App Start?

Hi,

I have a weird issue with SDL 2.0.3 on Microsoft Windows 8.1 Pro 64Bit.
When the SDL2 game first starts it registers a mouse button down event which I want to fix.
How can I clear all mouse button down events at application start in SDL2?

Thanks!



JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




Re: [2.0]-Clear Mouse Button Down Events At App Start?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
MrOzBarry wrote:
You could just run a loop like:

SDL_Event discard;
while (SDL_PollEvent(&discard)) {}


That will clear the event buffer, and stop once the first few events are fired.  You shouldn't, however, be getting a mouse down unless you're clicking.  Can you try starting your app from the command line; the app might be registering a click from double clicking the executable or something odd like that.  If the command line fixes that, then at least you know where the click is coming from.


-Alex
Hi,

I tried adding what you suggested right before the main loop of the game.
Still getting a mouse button down event right when the game starts?
I know it's a mouse button down event because my company screen skips immediately to title screen.
Only occurs when double-clicking the EXE and not when run from command prompt or Code::Blocks IDE.

Any other ideas?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Hi,

Still have issue with mouse button down at app start.

Here is my code:
Code:
    for (int index = 0; index < 3; index++)
    {
        if ( SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(index+1) )
        {
            if (MouseButtonWasClicked[index] == false)
            {
                MouseButtonPressed[index] = true;
                MouseButtonWasClicked[index] = true;
            }
        }
        else  MouseButtonWasClicked[index] = false;
    }


Am I doing something wrong?
Sparks


Joined: 01 Jun 2013
Posts: 47
JeZ-l-Lee wrote:
Hi,

Still have issue with mouse button down at app start.

Here is my code:
Code:
    for (int index = 0; index < 3; index++)
    {
        if ( SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(index+1) )
        {
            if (MouseButtonWasClicked[index] == false)
            {
                MouseButtonPressed[index] = true;
                MouseButtonWasClicked[index] = true;
            }
        }
        else  MouseButtonWasClicked[index] = false;
    }


Am I doing something wrong?

What is before your for loop?
You need a SDL_PumpEvents(); right before it, so the values of SDL_GetMouseState make sense.
BTW, why do you have MouseButtonPressed[index] = true; MouseButtonWasClicked[index] = true;? Seems redundant.
[2.0]-Clear Mouse Button Down Events At App Start?
Ryan C. Gordon
Guest

Quote:
BTW, why do you have MouseButtonPressed[index] = true;
MouseButtonWasClicked[index] = true;? Seems redundant.

It looks like in this case, one means "the button is pressed" the other
means "the button was pressed for the first time during this frame," I
think.

Jesse, is this only happening Windows (and is this source code somewhere
I can see?). I'd like to verify if this is an SDL bug before 2.0.4 is
finalized.

Thanks,
--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: [2.0]-Clear Mouse Button Down Events At App Start?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Ryan C. Gordon wrote:
Jesse, is this only happening Windows (and is this source code somewhere
I can see?). I'd like to verify if this is an SDL bug before 2.0.4 is
finalized.

Thanks,
--ryan.
Hi,

I was not doing "SDL_PumpEvents();" before the mouse button code so the problem might have been that?
The development desktop with Windows 8.1 Pro 64Bit blew a PCI network adapter and I am waiting for a replacement.
On my test desktop with Windows 8.1 Pro 64Bit native this issue is not occurring.
I should note that the problem was only on my broken desktop with Win 8.1 Pro 64Bit running in a VMWare Player 7 virtual machine
under a Linux Mint 17.1 KDE 64Bit host.

When I have the dev desktop back up and running I'll see if adding "SDL_PumpEvents();"to the source fixes the issue...
Thanks!
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Hi,

"SDL_PumpEvents();" does not solve the problem.

On Win 8.1 Pro 64Bit VMWare Player guest on Linux Mint 17.1 KDE 64Bit host
SDL2 registers a mouse button down when application is 1st run.
(only occurs when EXE is double-clicked)

Hope this can be fixed in 2.0.4, thanks!
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Here is the source code to "TetriCrisis 4 110% A.I. Turbo":
http://16bitsoft.com/TC4T/TetriCrisis4110PercentAITurbo.htm
(this web page is private from my Internet portfolio, please don't distribute it)

Hope this issue can be fixed, thanks!
macrofeet


Joined: 29 Apr 2012
Posts: 20
Same issue with left click starting app with double click

changed

if(event.button.button == SDL_BUTTON_LEFT) GoGame();

to

if(event.button.button == SDL_BUTTON_RIGHT) GoGame();


works correctly so seems like its registering the 2nd click as a click

while (SDL_PollEvent(&discard)) { SDL_Delay(100);} // This worked bit lame tho
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
macrofeet wrote:
Same issue with left click starting app with double click

...

while (SDL_PollEvent(&discard)) { SDL_Delay(100);} // This worked bit lame tho
Hi,

I tried what you typed and it does not work for me?
macrofeet


Joined: 29 Apr 2012
Posts: 20
SDL_Event event;

while (SDL_PollEvent(&event)) { SDL_Delay(1);}

weird I'm using it on the following game it works fine http://gamejolt.com/games/asteroids-flackroid-hd/52501