1

I just wanted to create a little thing that will stop me from clicking more than once on the left mouse button at the same time.

    click = pygame.mouse.get_pressed()

    if click[0] == 1:
        print ("lel")

In this code, if I stay pressed on my left mouse, it will print out very fast and very much "lel"s. I want to only execute the code once at a time so that it won't spam.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
nicobld
  • 131
  • 2
  • 12
  • Then set something to determine whether you've already handled a given mouse click. – jonrsharpe Feb 22 '16 at 19:55
  • @JonathonOgden Thank you ! It works fine now :) ! But why didn't you just answer with the answer button ? – nicobld Feb 22 '16 at 20:06
  • @Daemond-Creep I am not overly familiar with pygame - little hands-on experience - but I am a game developer in any case. Moved it to an answer instead. Glad it worked for you. – Jonathon Ogden Feb 22 '16 at 20:20

1 Answers1

1

I'd switch to using pygame.event.get() or pygame.event.wait() and print ("lel") when MOUSEBUTTONUP event is received. That way, you will print "on click" rather than "on held down" which is what is happening to you.

This has been covered here: Pygame mouse clicking detection

Community
  • 1
  • 1
Jonathon Ogden
  • 1,562
  • 13
  • 19