Are the text boxes part of the first application or a third application? The complexity of what you are proposing to do depends on the answer to this question.
If the text boxes belong to the first application you have absolute control of what goes into them and how. If they are part of a third application your first application is effectively replacing the third applications keyboard input.
Given your goals, the latter sounds more likely. Look up
freedesktop.org and also the
Inter-Client Communication Convenvtions Manual (ICCCM).
Best of luck
Andrew