Detecting all mouse clicks

Hi guys,

Is there a way to detect a certain mouse click like ‘mouse1’ or ‘mouse1-up’ no matter where it happens in the program (ie wether it is a button click or a click in an open space).

I am trying to implement a feature where the cursor of the mouse changes when the mouse button is clicked and changes again when released.

I have not found an easy way to do it so far. There are convoluted ways to achieve that, but i am trying to find something more reproducible in many situations and more streamlined way.

Thank you


Possible you need suppressMouse parameter

A post in another thread prompted a thought:

In a task – perhaps your main update task, if you have one – check the mouse button state via base.mouseWatcherNode and alter your cursor based on that. While you might experience lag, especially when your frame-rate is low, I think that it should work – but please note that I haven’t tried it myself.

Something like this:

# Initialisation code; this flag should prevent the code from attempting to change
#  the cursor every frame
self.mouseWasDown = False

# In a task somewhere...
if base.mouseWatcherNode.hasMouse():
    if base.mouseWatcherNode.isButtonDown(
        if not self.mouseWasDown:
            self.mouseWasDown = True
            # <change your cursor to reflect that the button is down>
        if self.mouseWasDown:
            self.mouseWasDown = False
            # <change your cursor to reflect that the button is up>

Note that you may still want to check that the “suppressMouse” keyword is set to “False” in all of your GUI elements.

DirectGUI manual page, including mention of “suppressMouse”, I believe.

Ensuring suppressMouse = False should be sufficient, though. That will generate the ‘mouse1’ and ‘mouse1-up’ whenever it occurs anywhere in the window.


Yes thank you, suppressMouse worked, i was not sure what it was for when i read it a while ago and then forgot about it.
Thanks for the help.