Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to capture user key strokes on Android?



  • How do I intercept every key stroke on Android platform when the user is typing keys on soft keyboard?

    I have this code, but it doesn't work:

            TextField {
                id: pick_city
                Layout.fillWidth: true
                placeholderText: "London"
                Keys.onPressed: {
                    console.log("pressed event")
                    console.log(event)
                }
                Keys.onReleased: {
                    console.log("pressed event:")
                    console.log(event)
                    if (pick_city.length>2) {
                        var cc=countries.get_country_code_by_index(combo_countries.currentIndex)
                        cities.net_get_city_list(cc,pick_city.text)
                    }
                }
            }
    

    Keys.onReleased (or onPressed) doesn't seem to work at all, the console.log() messages aren't printed. They are only printed if I hit BACKSPACE key. So, how do you listen for keys that the user is typing on soft keyboard in Android?
    I need to implement a City Picker, a very interactive search, sort of like the one Google uses when you type query in the input box and it shows you all the top-searched keywords.


  • Qt Champions 2017

    Can you try using

    Keys.forwardTo:[obj1] where obj1 receives the keys.



  • Nope. This is the code I tried:

            TextField {
                id: forward_item
                Layout.fillWidth: true
            }
            ComboBox {
                id: pick_cities
                Layout.fillWidth: true
                editable: true
                Keys.onPressed: {
                    console.log("pressed")
                }
                Keys.onReleased: {
                    console.log("released")
                }
                Keys.forwardTo: forward_item
    
            }
    

    works perfectly on Desktop, the keys are copied to forward_item. But on Android it doesn't forward anything. And the Key.onReleased or Keys.onPressed events are only received (all at once) when I press Done on the soft keyboard. Unfortunately, receiving these events all at once isnt useful in my case, since I have to make a search in the database (on every key stroke) to show only the Cities that match user's text.


Log in to reply