Handling a return or enter key event on an edit text control

Member
Posts: 353
Joined: 2002.04
Post: #1
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Use Cocoa... trying to use Carbon to make a standard Mac UI is completely insane.
Quote this message in a reply
Member
Posts: 353
Joined: 2002.04
Post: #3
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Of course, but the chances anyone actually knows /how/ are slim Rasp
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #5
...or anyone actually *remembering* how Rasp
Quote this message in a reply
elerion
Unregistered
 
Post: #6
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.
Quote this message in a reply
dair
Unregistered
 
Post: #7
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.
Quote this message in a reply
Member
Posts: 353
Joined: 2002.04
Post: #8
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Full Screen Event Handling kodex 4 4,753 Jun 27, 2008 08:37 PM
Last Post: OneSadCookie
  Return style Coin 13 4,498 Apr 22, 2006 12:11 AM
Last Post: OneSadCookie
  Event Handling (Keyboard and Mouse) bwalters 6 7,393 Mar 12, 2006 08:17 PM
Last Post: OneSadCookie
  State Tables and Event Handling geolycosa 1 2,519 Aug 29, 2005 12:58 PM
Last Post: ThemsAllTook
  Getting text from a window text field mars 7 4,815 Mar 26, 2005 06:06 PM
Last Post: OneSadCookie