Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    key in dialog [SOLVED]

    PYTHON Development
    0
    3
    352
    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.
    • H
      Helper
      last edited by

      On 18/01/2015 at 05:51, xxxxxxxx wrote:

      I try to get Keys within a dialog - with out success

      def CreateLayout(self) :
              self.SetTitle('Stage - Command Line')
              self.GroupBegin(GROUP, c4d.BFH_SCALEFIT, cols=1, title="Generator",)
              self.AddEditText(1001, c4d.BFH_SCALEFIT, editflags=c4d.EDITTEXT_HELPTEXT)
              self.SetString(id = 1001,value  = "enter a Stage command",flags = c4d.EDITTEXT_HELPTEXT)
             self.GroupEnd()
              return True
        
       def Command(self, id_, msg) :
              if id_ == 1001:
                  resultBaseContainer = c4d.BaseContainer()
                  self.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_ENTER,resultBaseContainer)
                  if resultBaseContainer[c4d.BFM_INPUT_VALUE]:
                      print self.GetString(1001)
              bc = c4d.BaseContainer()
              ok = c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_TAB, bc)
              if bc[c4d.BFM_INPUT_VALUE] == 1:
                  print "tab key"    
              bc = c4d.BaseContainer()
              ok = c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_ESC, bc)
              if bc[c4d.BFM_INPUT_VALUE] == 1:
                  self.Close()
      
      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 20/01/2015 at 03:02, xxxxxxxx wrote:

        Hi conner,

        I have demonstrated two ways in the following Message function.
        Please be careful!
        By default you need to call gui.GeDialog.Message(self, msg, result). If you fail to do so, C4D will probably freeze.
        If you detect a keyboard input, you may return True, to avoid further processing of the key.
        BUT, again be careful, especially with keys like Enter or Tab. The user expects certain behavior and may be disappointed, if he is no longer able to use the Tab key to switch between dialog elements.

        def Message ( self, msg, result ) :
                # Method A, querying a special key
                bc = c4d.BaseContainer()
                ok = c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_TAB, bc)
                if ok:
                    if bc[c4d.BFM_INPUT_VALUE] == 1:
                        print "tab key"
                        return True # if you don't return here, the Tab key will still have the default influence on your dialog
                        # This can get really confusing...
                ok = c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_ENTER, bc)
                if ok:
                    if bc[c4d.BFM_INPUT_VALUE] == 1:
                        print "enter"
                        return True
                # Method B - processing the input message, works nicely for normal keys
                if msg.GetId() == c4d.BFM_INPUT:
                    if msg.GetInt32(c4d.BFM_INPUT_DEVICE) == c4d.BFM_INPUT_KEYBOARD:
                        print "KEYBOARD: "
                        print msg.GetString(c4d.BFM_INPUT_ASC)
                        return True  # return True ONLY on keys you want to process, otherwise standard commands won't work anymore, as long as your dialog is active
                return gui.GeDialog.Message(self, msg, result)
        
        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 21/01/2015 at 01:57, xxxxxxxx wrote:

          Many Thanks for the solution

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