Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Registering Single Mouse Click  (Read 13433 times)

0 Members and 1 Guest are viewing this topic.

AdventWolf

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Registering Single Mouse Click
« 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.

Xorlium

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Registering Single Mouse Click
« Reply #1 on: September 04, 2010, 09:44:14 pm »
Code: [Select]
YourWindow.EnableKeyRepeat(false);

AdventWolf

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Registering Single Mouse Click
« Reply #2 on: September 04, 2010, 10:19:39 pm »
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?

Code: [Select]
#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;
}

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Registering Single Mouse Click
« Reply #3 on: September 04, 2010, 10:56:44 pm »
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.

AdventWolf

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Registering Single Mouse Click
« Reply #4 on: September 04, 2010, 11:05:55 pm »
Ah ok thanks I got it to work! So for other readers that have had this problem, here's the code:

Code: [Select]
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;
}

nalpam

  • Newbie
  • *
  • Posts: 1
    • View Profile
Registering Single Mouse Click
« Reply #5 on: October 17, 2011, 02:24:39 pm »
Thanks for providing the answer to the situation. I was asking myself how to achieve the same effect.

:wink:

 

anything