Game Development Community

GuiTextEditCtrls and the TAB key

by Rubes · in Torque Game Engine · 01/26/2008 (2:41 pm) · 1 replies

Okay, this one has me baffled.

As with a previous post on this topic, I am using the ChatHud that was created for TGE's starter.fps kit as my main text output control, and the MessageHud that goes with it as the main text entry control. The MessageHud is basically a control that contains MessageHud_Edit, which is the GuiTextEditCtrl used for entering text.

The problem I am having is when the MessageHud_Edit control is brought up and the player hits the TAB key.

Nothing appears to happen when the TAB key is pressed -- the cursor still is visible in the GuiTextEditCtrl, you can continue typing and it will appear in the GuiTextEditCtrl, and you can press RETURN and the text that was entered will be processed appropriately. So I can't figure out what actually happens when the TAB key is pressed while the MessageHud is open. But something definitely does happen.

The reason is this: If you press TAB and then continue typing as usual and hit RETURN to process the text and make the MessageHud go away, bringing the MessageHud back up causes the program to crash. Interestingly, the crash occurs in GuiTextEditCtrl::onKeyDown(). So the keypress which is supposed to bring up the MessageHud is actually still being processed by the GuiTextEditCtrl. Somehow, once the TAB key is pressed, the MessageHud doesn't seem to be closed properly even though subsequent typing appears as it should, and hitting RETURN does appear to make the MessageHud go away properly. But something is wrong, and I can't figure out what.

One thing I have found is that, if you hit the TAB key and then click the mouse within the text field of the GuiTextEditCtrl, it will proceed to work normally, no crashing. So it sounds like hitting TAB might cause the focus to move from the GuiTextEditCtrl to some other control. But this doesn't make sense, since the cursor still appears in the GuiTextEditCtrl and typing will still work as it should.

I also went into the engine code, in GuiTextEditCtrl.cc, and commented out the section in GuiTextEditCtrl::onKeyDown() that handles all KEY_TAB events. No change -- pressing TAB still causes the same problem.

Any thoughts on this? I'm baffled.

#1
01/26/2008 (3:04 pm)
Ah well...I figured it had to be the control losing focus to another control somehow. So I just used a workaround that captures TAB key presses in the keyMap when the MessageHud is open, and sends an immediate "MessageHud_Edit.makeFirstResponder(true);" command. That works fine -- no more crashes from the TAB key.