Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
detecting mouse not working
#3
To clarify a bit more, I think this is the crux of the issue:

Take the following snippet:
for event in pg.event.get():
    if event.type == pg.MOUSEBUTTONDOWN:
        mouse_clicked = True
    elif event.type == pg.MOUSEBUTTONUP:
        mouse_clicked = False

if mouse_clicked:
    run_on_click()
You seem to be assuming that if the mouse is clicked, the function at the bottom will always run. This isn't the case. The event queue can potentially have both a MOUSEBUTTONDOWN and MOUSEBUTTONUP event in it at the same time. This means that by the time your event loop is finished your mouse_clicked variable could have been set to True and then back to False before reaching the end of the code and running the function in the conditional.

If you want something to fire immediately on an event you will need it to, well, fire immediately on that event:
for event in pg.event.get():
    if event.type == pg.MOUSEBUTTONDOWN:
        run_on_click()
Again as I said previously this comes down to the fact that the way you are trying to design the key handler is currently not ideal.
Reply


Messages In This Thread
detecting mouse not working - by TheNumericDolfin - Aug-23-2018, 12:45 AM
RE: detecting mouse not working - by Mekire - Aug-23-2018, 12:53 AM
RE: detecting mouse not working - by Mekire - Aug-23-2018, 01:15 AM
RE: detecting mouse not working - by Windspar - Aug-23-2018, 01:19 AM
RE: detecting mouse not working - by Mekire - Aug-23-2018, 01:33 AM
RE: detecting mouse not working - by Windspar - Aug-23-2018, 01:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  iterating and detecting the last Skaperen 3 1,157 Oct-01-2022, 05:23 AM
Last Post: Gribouillis
  Detecting float or int in a string Clunk_Head 15 4,905 May-26-2022, 11:39 PM
Last Post: Pedroski55
  module detecting if imported vs not Skaperen 1 1,730 Nov-19-2021, 07:43 AM
Last Post: Yoriz
  detecting a generstor passed to a funtion Skaperen 9 3,790 Sep-23-2021, 01:29 AM
Last Post: Skaperen
  Python BLE Scanner not detecting device alexanderDennisEnviro500 0 2,070 Aug-01-2021, 02:29 AM
Last Post: alexanderDennisEnviro500
  Detecting power plug Narayan 2 2,795 Aug-01-2020, 04:29 AM
Last Post: bowlofred
  Detecting USB Device Insertion on Windows 10 Atalanttore 0 2,469 Jan-17-2020, 02:46 PM
Last Post: Atalanttore
  mouse 0.7.0 - mouse polling hate 125-1000hz penahuse 1 2,607 Dec-06-2019, 09:51 PM
Last Post: Larz60+
  Detecting windows shutdown event riccardoob 4 5,868 Nov-12-2019, 04:51 PM
Last Post: Aurthor_King_of_the_Brittons
  Why is left mouse click not working? yeto 3 6,331 Jul-15-2019, 05:23 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020