SFML community forums
Help => Graphics => Topic started by: AdventWolf on September 04, 2010, 09:33:46 pm
-
Hello, I've lurked here for a while to help solve some problems here and there and I have searched for the answer to the problem I have now, but I haven't found much solid info.
I am trying to use the mouse to select buttons in a program, but holding the mouse down for longer than half a second will output the button multiple times.
How can I fix it so that the button won't be initiated until I release the mouse click on the button?
Thanks.
-
YourWindow.EnableKeyRepeat(false);
-
I guess I must be doing something wrong, I have tried that, but I still get infinite output if the mouse is held down.
What is wrong with this sample?
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow App(sf::VideoMode(600,600),"Test");
App.EnableKeyRepeat(false);
while( App.IsOpened() )
{
const sf::Input& Input = App.GetInput();
App.GetInput().GetMouseX(), App.GetInput().GetMouseY();
sf::Event Event;
while( App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
if( Input.IsMouseButtonDown(sf::Mouse::Left) )
std::cout << "left" << std::endl;
App.Display();
}
std::cout << "DONE" << std::endl;
}
-
You're checking if the mouse mouse button is pressed every frame. So as long as you press the mouse button this will return true.
-
Ah ok thanks I got it to work! So for other readers that have had this problem, here's the code:
while( App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
else if( Event.Type == Event.MouseButtonReleased && Event.MouseButton.Button == sf::Mouse::Left )
std::cout << "LEFT" << std::endl;
}
-
Thanks for providing the answer to the situation. I was asking myself how to achieve the same effect.
:wink: