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

Author Topic: Problem with MouseButtonPressed  (Read 9575 times)

0 Members and 1 Guest are viewing this topic.

Romsik788

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problem with MouseButtonPressed
« on: June 12, 2020, 02:57:25 pm »
I have code

if (event.type == Event::MouseButtonPressed)
        {
            if (event.key.code == Mouse::Left)
            {
                  //Some code
            }
        }

I need that when long hold down the left mouse button this code does not work. (When you click on the mouse, this code should work once, while further holding mouse down, the code should not work) How to do it?
P.S. Sorry my english  ;)
« Last Edit: June 12, 2020, 02:59:15 pm by Romsik788 »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Problem with MouseButtonPressed
« Reply #1 on: June 12, 2020, 03:39:49 pm »
Your code is incorrect. Instead of this:
if (event.key.code == Mouse::Left)

You should do this:
if (event.mouseButton.button == Mouse::Left)

event.key.code is for keyboard events.

Romsik788

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Problem with MouseButtonPressed
« Reply #2 on: June 12, 2020, 04:33:41 pm »
Fixed, but this still did not solve my problem

Romsik788

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Problem with MouseButtonPressed
« Reply #3 on: June 12, 2020, 08:23:06 pm »
I fixed the problem, it was necessary to put this code in the event loop. As a result, I have this:

Event event;
while(window.pollEvent(event))
        {
            if (event.type == Event::Closed)
                {
                    window.close();
                }
            if (event.type == Event::MouseButtonPressed)
                {
                    if (event.mouseButton.button == Mouse::Left)
                        {
                            //Some code
                        }
                }
         }
« Last Edit: June 12, 2020, 08:38:38 pm by Romsik788 »