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:
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!