0

Halo Great People?

I am new learning Kotlin.

I am trying to programmatically tap on a button on the keyboard after its called.

Here, after when focused on an edit text, calling showKeyboard(), the keyboard appears, I would like to tap on a key, (e.g. 'a') programmatically.

here's what I have so far...

button.setOnClickListener {
            showKeyboard()
        /** If possible have the code to tap on a button programmatically here...*/
}



private fun showKeyboard() {
        val imm = this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
    }

Any help is highly appreciated! Thanks, take care.

  • 1
    What you want is not possible, except perhaps on rooted devices or *maybe* by using accessibility services. The soft keyboard (or other form of input method editor) is a separate app in a separate process; you cannot send UI input events to other apps, for privacy and security reasons. – CommonsWare Jan 20 '21 at 00:51
  • Why don't set the text in the `EditText`? If you want a text to fix in the view then there are different approaches to do that. – Himanshu Choudhary Jan 20 '21 at 04:22
  • [This](https://stackoverflow.com/a/35753675/9701793) may answer you. – rahat Jan 20 '21 at 14:13

0 Answers0