I've been using this code below to enter in numeric values with a decimal. This seems to work fine, however, when there are 2 decimals in the field I want to continue to allow the entry of these valid characters if the cursor is before the decimal place with two digits. I therefore need to change this line of code "if length (item 2 of me) = 2 then exit keyDown" to detect the cursor position, and pass KeyDown if the number being keyed in is before the decimal with two digits. Can someone help me with the relevant code. I thought I could get cursor/caret position and then compare it with where the decimal, pass keydown if its before else exit keydown, but cant fund the commands i need in the dictionary.
Code: Select all
on keydown tKey if tKey is in "-1234567890." then if "." is in me then if tKey is "." then answer "You cannot have more than 1 decimal in this field" exit keyDown else set the itemDelimiter to "." if length (item 2 of me) = 2 then exit keyDown pass keyDown end if end if pass keyDown end if end keydown