I actually made such a function for a client some time ago where if the user clicked on a text field, which was really just a simple image rect in this case, the app started to listen for event.keyNames. As the user inputted keys, I simply added them to the string and updated the text display object.
In addition to that, I only needed to add a few other tricks like, if there is already text on the “text field” when the user clicks it, then I used event.x and event.y to calculate where on the string the user clicked and made that the active text input location. Additionally, I needed to write what happens when the user presses enter, delete, backspace, arrow keys, etc.