This can be made better if the presence of the cursor can be detected. For example:
INEDIT CURSPOS k
Returns the position of the cursor in the edit field with the object index k. The position equals the number of characters before the cursor, including spaces. If zero then the cursor is on the left side of the field. If the return value is -1 then the cursor is not in field k.