How to detect CTRL being pressed in a GeDialog
-
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. -
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.
-
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. -
Thanks @m_adam
I can confirm that the following does work with R20, R23 and 2023Int32 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;
-
-