Hey, I'm interested in controlling the properties of text as it is being entered into a field. Specifically, I'm making a chemistry application and need to distinguish numbers and letters, then would like to make all the numbers to be subscript as I type them in. The following code works but is a bit too simple:
Code: Select all
on keyDown tKey
put toUpper (tKey) after fld "test"
put the length of fld "test" into y
if isNumber (char y of fld "test") is true then
set the textSize of char y of fld "test" to 10
set the textShift of char y of fld "test" to 3
else if matchText (char y of fld "test", "[A-Z]") is true then
set the textSize of char y of fld "test" to 12
set the textShift of char y of fld "test" to 0
end if
end keyDown
The problem is that I always add the new characters at the end of the string. If someone makes a mistake and moves the cursor to the middle, deletes a character and retypes, my code sticks the changes at the end. How to I poll the cursor position? I think this should be easy to do, but can't find the proper handler to access the position in the text the ibeam is located.
Sorry if this seems trivial, but it's amazing how simple things can completely stall progress.
--Doug