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

    How to detect CTRL being pressed in a GeDialog

    Cinema 4D SDK
    r23 r25 2023 c++
    2
    4
    909
    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.
    • C4DSC
      C4DS
      last edited by

      I am in a GeDialog and have a button that is by default disabled.
      I want to enable it as long as CTRL key is being pressed.

      1 Reply Last reply Reply Quote 0
      • C4DSC
        C4DS
        last edited by

        The following works in R20

        Int32 MyDialog::Message(const BaseContainer& msg, BaseContainer& result)
        {
        	BaseContainer keyChannels;
        	if (GetInputEvent(BFM_INPUT_KEYBOARD, keyChannels))
        	{
        		const Int32 qualifier = keyChannels.GetInt32(BFM_INPUT_QUALIFIER);
        		ApplicationOutput("qualifier @", qualifier);
        	}
        

        It shows a value '2' when I press CTRL key, '0' when I let go.

        But in R23 (and above), I don't get any output in console window.

        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by m_adam

          Hi @C4DS this has indeed changed, I will check with the UI team to know the exact reason. To retrieve qualifier I find out that only GetInputState is working, so in the meantime you can do this like that and it work as expected

              def Message(self, msg, result):
                  res = c4d.BaseContainer()
                  self.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.QCTRL, res)
          
                  if res[c4d.BFM_INPUT_QUALIFIER]:
                      print(msg.GetId())
                      isShiftPressed = bool(res[c4d.BFM_INPUT_QUALIFIER] & c4d.QSHIFT)
                      isCtrlPressed = bool(res[c4d.BFM_INPUT_QUALIFIER] & c4d.QCTRL)
                      isAltPressed = bool(res[c4d.BFM_INPUT_QUALIFIER] & c4d.QALT)
          
                      print(f"{isShiftPressed=}, {isCtrlPressed=}, {isAltPressed=}")
                      print("----------------------------")
          
                  return c4d.gui.GeDialog.Message(self, msg, result)
          

          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • C4DSC
            C4DS
            last edited by

            Thanks @m_adam
            I can confirm that the following does work with R20, R23 and 2023

            Int32 MyDialog::Message(const BaseContainer& msg, BaseContainer& result)
            {
            	BaseContainer keyChannels;
            	if (GetInputState(BFM_INPUT_KEYBOARD, QCTRL, keyChannels))
            	{
            		Bool ctrlModifier = (keyChannels.GetInt32(BFM_INPUT_QUALIFIER) & QCTRL) != 0;
            
            
            1 Reply Last reply Reply Quote 0
            • M m_adam referenced this topic on
            • M m_adam referenced this topic on
            • First post
              Last post