Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Unable to Detect Mouse Click

    Cinema 4D SDK
    r21 python
    3
    7
    1.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bentraje
      last edited by

      Hi,

      I have this edited code snippet from Cineversity. The example is using keyboard but I'm trying to access the mouse click. Should I have additional settings for the mouse inputs? Thank you for looking at my problem.

              # This one works 
              if id in all_button_ids:
                  self.Close()
                  return True
      
              # This one does not 
              bc = c4d.BaseContainer()
              if c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE,c4d.BFM_INPUT_MOUSELEFT,bc):
                  if bc[c4d.BFM_INPUT_VALUE]==1:
                    self.Close()
                    return True
      
      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hello ,

        In what context are you using this function ?

        you can have information on this manual talking about Mouse and Keyboard Interaction

        You also have the liquid tool that show how to check the mouse input.

        Something like this should work

        def main():
            bc = c4d.BaseContainer()
            if c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE,c4d.BFM_INPUT_MOUSELEFT,bc):
                if bc[c4d.BFM_INPUT_CHANNEL]== c4d.BFM_INPUT_MOUSELEFT:
                    print "left mouse"
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • B
          bentraje
          last edited by

          @m_magalhaes

          Thanks for the response.

          RE: In what context are you using this function ?
          I'm trying to create pop-up dialog. I want it to close when I click a command. That's figured it out.
          I also want it to close if I just click somewhere that's not a button hence the MOUSELEFT. That's the part I am having a problem with.

          RE: Something like this should work
          Apparently, it doesn't detect the mouse click still.

          I also tried the if msg[c4d.BFM_INPUT_CHANNEL]==c4d.BFM_INPUT_MOUSELEFT from the liquid tool. And it does not seem to detect it.

          You can see the current code here:
          https://www.dropbox.com/s/4b8czh5w2qzt8xx/bt_popup_commands.pyp?dl=0

          Thank you for looking at my problem.

          1 Reply Last reply Reply Quote 0
          • ManuelM
            Manuel
            last edited by Manuel

            hello,

            ok,

            something like this seem to work. Let me know.
            Be aware that the right click is catched for the popmenu that doesn't seem to send any INPUT message to the DialogBox.

                def Message(self, msg, result):
                    theID = msg.GetId()
                    if theID == c4d.BFM_INPUT:
                        if msg[c4d.BFM_INPUT_DEVICE] == c4d.BFM_INPUT_MOUSE:
                            if msg[c4d.BFM_INPUT_CHANNEL] == c4d.BFM_INPUT_MOUSELEFT:
                                if self.IsOpen():
                                    print 'left mouse close'
                                    self.Close()
                            elif msg[c4d.BFM_INPUT_CHANNEL] == c4d.BFM_INPUT_MOUSEMIDDLE:
                                print 'middle mouse'
                            elif msg[c4d.BFM_INPUT_CHANNEL] == c4d.BFM_INPUT_MOUSERIGHT:
                                print "right mouse"
                        
                    elif theID == c4d.BFM_LOSTFOCUS :
                        if self.IsOpen():
                            print "lost focus, close"
                            self.Close()
                   
                    return c4d.gui.GeDialog.Message(self, msg, result)
            

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

            1 Reply Last reply Reply Quote 2
            • B
              bentraje
              last edited by

              @m_magalhaes

              Thanks for the response. Works as expected.
              I didn't know that the Message function can also executed commands. I thought every command should be in the Command function.

              RE: Be aware that the right click is catched for the popmenu
              No worries. I don't use the RMB for my code so far.

              Thanks again! 🙂

              1 Reply Last reply Reply Quote 0
              • U
                unti
                last edited by

                Can I modify this code to 'catch' the right or middleclick in the viewport / editor befor it is doing the internal function?

                I was trying to get the middleclick in the editor and I can detect it, but it will always switch between four-split and one window editor layout. - I don't want this to happen.

                1 Reply Last reply Reply Quote 0
                • ManuelM
                  Manuel
                  last edited by

                  hello,

                  Please @unti open your own thread. The context is maybe a bit different and your question is a bit different.

                  Cheers,
                  Manuel.

                  MAXON SDK Specialist

                  MAXON Registered Developer

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post