Plugin runs twice on Enter?
-
On 28/03/2017 at 10:08, xxxxxxxx wrote:
I'm using this code to essentially set the enter key equal to hitting the "search" button on my plugin but it runs twice when I hit enter for some reason which screws things up.
[Update] I found that if just the plugin window is selected when I press "enter" it only runs once, but if the the edit text field in the plugin is highlighted(waiting for user to type) it runs twice? It's like its running once for the edit text field and once for the plugin itself.
bc = c4d.BaseContainer()
if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_ENTER,bc):
if bc[c4d.BFM_INPUT_VALUE] == 1:
id = UI_SEARCH -
On 28/03/2017 at 12:15, xxxxxxxx wrote:
https://developers.maxon.net/docs/py/2023_2/modules/c4d.gui/GeDialog/index.html#GeDialog.KillEvents
Will probably fix it
-
On 28/03/2017 at 12:58, xxxxxxxx wrote:
Thanks Gr4ph0s, this sounds like what I'm looking for but I'm not sure where exactly its supposed to be called. I tried putting it right after my code and it still runs twice:/
-
On 28/03/2017 at 13:32, xxxxxxxx wrote:
Looking a bit the c++ manual. https://developers.maxon.net/docs/cpp/2023_2/page_manual_gedialog.html#page_manual_gedialog_interaction
It's called into the message function at the end. Then basicly make a class variable and store the Enter state into the Message function then in Command plugin you can test it. -
On 28/03/2017 at 13:51, xxxxxxxx wrote:
I'm still kind of a noob so that went a little over my head but I'll see what I can do:)
-
On 29/03/2017 at 05:40, xxxxxxxx wrote:
Hi,
Yes, the enter key event is sent twice when the edit text is the active gadget in the dialog.
You are running the posted code in GeDialog::Command(), right?
To prevent processing the event twice, check the passed gadget id:
It is c4d.IDC_OK when the enter key is pressed and the event is triggered by the dialog. When the edit text triggers the event, id is the edit text ID.So you don't need to retrieve the enter key state and you can just check the value of id for c4d.IDC_OK.
Note the gadget ID c4d.IDC_OK is related to the Ok button when AddDlgGroup(c4d.DLG_OK) is used.
But c4d.IDC_OK is also used to notify the enter key has been pressed in a dialog even if there's no Ok button.
Note id in Command() is c4d.IDC_CANCEL when escape key is pressed. -
On 29/03/2017 at 07:39, xxxxxxxx wrote:
Great, thanks Yannick! Worked like a charm and was such an easy solution. If I would have been checking my id values I would have seen that the Enter key id also equals 1.
Cheers!