macoslib KeyUp event missing?

Hi,
does anyone know how to check for the return key being pressed from within an NSSearchField (macoslib)?
There seems to be no keyDown or KeyUp events?

Thanks.

why do you need it?
I think NSSearchField works just like all the search fields in OSX (Spotlight …)

I am using the field as a regular search field, and when the return key is pressed, I need the default button to fire it’s action event.

In spotlight, you can press enter / return and an event fires, (or a method is called).

then you need to probably take a textfield.

to make round corners, write this in the Open Event.

declare Sub setBezelStyle Lib "Cocoa" Selector "setBezelStyle:" (handle As Integer, value As Integer) setBezelStyle(Me.Handle, 1) Declare sub setFocusRingType lib "Cocoa" Selector "setFocusRingType:" (handle As Integer, type as Integer) setFocusRingType(Me.Handle, 1)

Thanks Axel.

I already use rounded textfields, but they do not contain the magnifying glass icon, or the “X” to clear the entry :frowning:
That is why I decided to use an NSSearchField.

Thanks anyway.

In the Cocoa Module of macoslib is the NSSearchField, you can add an EventDefinition

Event Name - KeyDown
Parameter - key as string
Return Type - boolean

Thank you very much - I will look into that :slight_smile:

Hmmmm - just tried that and nothing happens?

Adding an event definition will not cause the event to be fired, you would have to fire it yourself, which leaves you back at the drawing board trying to figure out when to fire the event. From what I can tell from the apple docs, this is not possible in an NSSearchField. Why do you need to know when the return key is pressed? There may be a better way to do this…

Jason,
I obviously ALSO added code in this new even chandler to check for the return key being pressed :slight_smile:

// CHECK FOR THE RETURN KEY BEING PRESSED if asc(key)=13 or asc(key)=9 then MsgBox("test") End if

I need to call a method when the return key is pressed after entering text in the NSSearchField.

I think you might have miss-read what I typed:

In order for the event to actually be called, you must raise it from the NSSearchField class, it will not be called by the Xojo (or Cocoa) framework just because it exists. This means that you have to figure out when to fire the event yourself from in the NSSearchField class, which…[quote]From what I can tell from the apple docs, this is not possible in an NSSearchField.[/quote]
Basically, it can’t be done the way you want to do it…

What will the method do? It is possible it is built into the NSSearchField class.

Jason,
It takes the text entered, and then searches a website for corresponding text.

(I hope this won’t appear twice because I could swear I hit the “Post” button …)

Richard,
in a Container control holding a NSSearchfield I handled a similar thing by adding a keyup event handler to the container control itself. In this I check for key being chr(13) or chr(3) and if call a method using the NSSearchfields string value as parameter. Did you try something like that?

Thanks Ulrich.
I put the code into the window keyup event, and it is now all working fine :slight_smile:

Me.LikingToHear (LastPost) = True