Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to capture user key strokes on Android?
Forum Updated to NodeBB v4.3 + New Features

How to capture user key strokes on Android?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 660 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nulik
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Can you try using

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

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nulik
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved