key in dialog [SOLVED]
-
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()
-
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)
-
On 21/01/2015 at 01:57, xxxxxxxx wrote:
Many Thanks for the solution