Need help Filtering keyboard entry in textView

Using XCode 3.2.1 on Snow Leopard and creating an Applescript ObjectiveC project.

I an trying to figure out how to do two things:

  1. Call an event upon each keypress in a text field.
    Use Case: As user enters text, upon each keystroke, gather the text in the active text field, process it, concatenate the string with another stored string, and display it in a text View.

I know how to do everything except the dynamic part, (i.e. upon each key stroke)

  1. I need to limit the range of characters entered in a text Field while it is being entered.
    Use Case: I only want to allow the characters quoted here “abcdefghijklmnop123456789ABCDEFGHIJKLMNOP_-()”
    Perhaps show an icon, or other visual queue that the user is trying to enter an invalid key if they type an unacceptable character.

Then I want to combine the two operations above display the text as it is entered.

James Haney

Try making your script a delegate of the text field, and use controlTextDidChange:.

Thanks Shane,

I figured it out based upon another similar post earlier today.

Now, I want to show a warning when the user types more than the allotted number of characters, and I want the text to be red.

I kind of have it working by having either nothing, or the warning string in a text box set to background color.

It seems that hiding and showing text fields, or coloring the text red is not exactly simple.

Of course you’ll want to consider a case in which someone hits the delete button, potentially reducing the number of characters in the field to less than 8, you might, then, want to change the color of the text back to its original color.

It’s better to bind the string value of the text field to a property in your code, but I can’t give you example code that uses binding, so I went the other route.

to limit the range of characters entered in a text Field while it is being entered:

elspub,

Thanks a ton for the coloring help, works like a charm.