iDevGames Forums
Handling a return or enter key event on an edit text control - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Handling a return or enter key event on an edit text control (/thread-4831.html)



Handling a return or enter key event on an edit text control - monteboyd - Nov 5, 2005 01:52 AM

In my game editor I'm trying to get an edit text control and a little arrows control to work together the way they do on the clock control and I'm having a bit of trouble.

Basically I can't figure out how to find out if the return or enter key is pressed while the edit text control is selected. What kind of event handler do I use?

Is there a simple way of getting a control like this up and running?


Handling a return or enter key event on an edit text control - OneSadCookie - Nov 5, 2005 02:36 AM

Use Cocoa... trying to use Carbon to make a standard Mac UI is completely insane.


Handling a return or enter key event on an edit text control - monteboyd - Nov 5, 2005 04:59 AM

Yes well I thought you might say that.

But it's a bit far gone to switch to Cocoa now, at least I'd like to try to get this working in Carbon first before I take that big of a step. Surely it is possible to have a standard edit text control work the way you'd expect it to using Carbon?


Handling a return or enter key event on an edit text control - OneSadCookie - Nov 5, 2005 03:10 PM

Of course, but the chances anyone actually knows /how/ are slim Rasp


Handling a return or enter key event on an edit text control - AnotherJake - Nov 5, 2005 03:44 PM

...or anyone actually *remembering* how Rasp


Handling a return or enter key event on an edit text control - elerion - Nov 5, 2005 04:01 PM

I'm not actually sure if this works, because i never used EditText fields with Carbon before. But my suggestion is that you could use a normal event loop to check for the return key and then verify with "GetKeyboardFocus(...)" if the EditText field is selected.


Handling a return or enter key event on an edit text control - dair - Nov 7, 2005 07:15 AM

monteboyd Wrote:Basically I can't figure out how to find out if the return or enter key is pressed while the edit text control is selected. What kind of event handler do I use?
If you can require 10.3 or later, register for a { kEventClassTextField, kEventTextAccepted } event (HIView.h). This will be sent when the user hits enter/return and the focus is in an edit field, combo box, or search field (or when the field had the focus and loses it: i.e., it's a generic "user has accepted this value" event for text views).

If you have to support pre-10.3, you can attach a { kEventClassKeyboard, kEventRawKeyDown } handler to the control with InstallControlEventHandler and then trigger your action when you see the keystroke come in.

OneSadCooki Wrote:Use Cocoa... trying to use Carbon to make a standard Mac UI is completely insane.
That's nonsense.


Handling a return or enter key event on an edit text control - monteboyd - Nov 7, 2005 03:29 PM

Thanks elerion, I attached a raw key event to the edit text box and then use GetKeyboardFocus and that works. However I might try dair's suggestion as that would mean not having to check for the return key, the enter key, the tab key etc manually.

Thanks guys.