The keyboard communicates with the system via an interface (API) from the OS (Android/iOS) to send text, actions, etc... to the textfield, which is part of the App where the user is writing.