Game Development Community

Enhancement: Numpad Enter Support for guiTextEditCtrl

by David Wyand · in Torque Game Engine · 06/17/2004 (9:59 am) · 5 replies

Greetings!

I've discovered that the numpad Enter key is not supported by the guiTextEditCtrl. It can be frustrating to type in a number with the numpad but have to go waaaay over to the keyboard's return key. So, here's how to add that support.

Open up guiTextEditCtrl.cc and go to the onKeyDown() method. Look for the following code:

case KEY_RETURN:
            //first validate
            onLoseFirstResponder();
            mHistoryDirty = false;

Now add the following:

case KEY_RETURN:
         [b]case KEY_NUMPADENTER:[/b]
            //first validate
            onLoseFirstResponder();
            mHistoryDirty = false;

And that's it! Enjoy!

- LightWave Dave

About the author

A long time Associate of the GarageGames' community and author of the Torque 3D Game Development Cookbook. Buy it today from Packt Publishing!


#1
06/17/2004 (3:59 pm)
Good fix. Checked this in.
#2
06/17/2004 (6:32 pm)
Question about the coding: does placing the two case expressions together like you show act like an OR?
#3
06/17/2004 (7:02 pm)
@Desmond: Yes, in C/C++, if you do not put a break; command at the end of a case body, run flow will "fall through" to the next case. This can be really nifty when you have certain sets of cases that all need a small base of common things to happen, and maybe 1 or 2 unique ones--but it can also be a nightmare when you accidentally forget the break, and can't figure out what is going on.

In that specific example it acts as an "or", but in general, it's more of a "do this, and then do this, and then do this" until you hit the break (or end of the switch).
#4
06/17/2004 (9:30 pm)
It's sort of parallel to gotos and labels.
#5
06/17/2004 (10:37 pm)
Ben's got it. In fact, switch/case just gets translated into a string of simple assembly-language compares and jumps.