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

    Adding Keyboard Message: KEY_ENTER & KEY_TAB

    Cinema 4D SDK
    3
    4
    565
    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.
    • ?
      A Former User
      last edited by A Former User

      Hello,
      I would like to request that KEY_ENTER and KEY_TAB are added to the Keyboard Message's Channel.

      This issue has come up several times in the forum. There are some workarounds, it seems, but they aren't nearly as straightforward as checking the Channel's value:

      • [key in dialog [SOLVED]](https://developers.maxon.net/forum/topic/8455
      • GetInputEvent - Enter Key
      • Unnecessary Executions Under BFM_INPUT_VALUE

      I'm sure there are reasons those two keys weren't included, but it would be very helpful if this implementation could be revisited.

      For anyone facing this issue, here are some workarounds in a script:

      import c4d
      from c4d import gui
      
      GROUP_ID1=1000
      TEXT_FIELD=1001
      
      class KeyDlg(gui.GeDialog):
          def CreateLayout(self):
              self.SetTitle("Key Test")
              if self.GroupBegin(GROUP_ID1, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 1, 1):
                  self.GroupBorderNoTitle(c4d.BORDER_THIN_IN)
                  self.AddStaticText(TEXT_FIELD, c4d.BFH_CENTER | \
                  c4d.BFH_SCALE | c4d.BFV_CENTER | c4d.BFV_SCALE, 0, \
                  0, "Press the Enter Key")
              self.GroupEnd()
              return True
      
          def Message (self, msg, result):
              if msg.GetId() == c4d.BFM_INTERACTSTART:
                  bc = c4d.BaseContainer()
                  if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_TAB, bc):
                      if bc[c4d.BFM_INPUT_VALUE] == 1:
                          print(c4d.KEY_TAB,"Tab")
                          self.SetString(TEXT_FIELD,"Tab")
                          self.LayoutChanged(TEXT_FIELD)
                          return True
                  if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_ENTER, bc):
                      if bc[c4d.BFM_INPUT_VALUE] == 1:
                          print(c4d.KEY_ENTER,"Enter")
                          self.SetString(TEXT_FIELD,"Enter")
                          self.LayoutChanged(TEXT_FIELD)
                          return True
              if msg.GetId() == c4d.BFM_INPUT:
                  if msg.GetInt32(c4d.BFM_INPUT_DEVICE) == c4d.BFM_INPUT_KEYBOARD:
                      channel = msg.GetInt32(c4d.BFM_INPUT_CHANNEL)
                      txt = msg.GetString(c4d.BFM_INPUT_ASC)
                      if channel == c4d.KEY_SPACE:
                          txt = "Space"
                      elif channel == c4d.KEY_LEFT:
                          txt = "Left"
                      elif channel == c4d.KEY_RIGHT:
                          txt = "Right"
                      elif channel == c4d.KEY_UP:
                          txt = "Up"
                      elif channel == c4d.KEY_DOWN:
                          txt = "Down"
                      print(channel,txt)
                      self.SetString(TEXT_FIELD,txt)
                      self.LayoutChanged(TEXT_FIELD)
                      return True
              return gui.GeDialog.Message(self, msg, result)
      
      dlg = KeyDlg()
      dlg.Open(c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=50)
      

      Thank you!

      1 Reply Last reply Reply Quote 0
      • indexofrefractionI
        indexofrefraction
        last edited by

        thats a nice one, thank you!

        enter and tab works!
        can't get the last part to work here, tough (c4d.BFM_INPUT)

        1 Reply Last reply Reply Quote 0
        • ?
          A Former User
          last edited by A Former User

          @indexofrefraction I just tested and it works with my setup. Most of the code comes from former SDK team member Andreas' post here. Perhaps test that? If it doesn't work, I would open a new thread.

          I'd prefer to keep this topic on the KEY_ENTER & KEY_TAB request please.

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

            hi,

            @indexofrefraction, as @blastframe said, let's keep that thread clean and ask your question in another thread, this is working on my system.

            @blastframe , we will take into consideration your request.

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

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