ADB keycodes fail to search using Android keyboard Search key vs Enter Key

断了今生、忘了曾经 提交于 2019-12-13 13:45:21

问题


Why could a particular text field/search bar fail to trigger search when sending the Search or Enter keycodes?

  • On the Android Keyboard, is the Search key the Enter key with a metastate? Or is it a completely different key?
  • What is the metastate of the Search Key? Or is it its own keycode?
  • Does the Android key code KEYCODE_ENTER press the search key? Or does KEYCODE_SEARCH?

I had the same problem as this fellow and came up with a fix (below): Unable to click the Search(magnifying glass) button in Android keyboard using Appium/Selenium/Java.

While my question is related, the question I have is what is the metastate of the Search Key on the Android Keyboard, and why doesn't KEYCODE_ENTER work? Why doesn't KEYCODE_SEARCH work? I care less about how to fix it and more about why this is happening (so that I can fix it myself).

I'm trying to interact with an application via adb using the command line/appium:

  • adb shell input keyevent KEYCODE_ENTER
  • adb shell input keyevent KEYCODE_SEARCH

Example

Take the google search bar widget for example. What exactly is happening to the enter key to make it into a magnifying glass? I am a black box tester, so I don't get access to the code I'm working with.

Follow these steps to see what I'm talking about:

  1. Tap on the Google Search Bar to focus on the field and bring up the soft keyboard.
  2. Notice that the Google Search Bar changes the keyboard to display the enter key as a magnifying glass.
  3. Input the text "birds" (don't hit enter yet).
  4. In command line, run adb shell input keyevent KEYCODE_SEARCH
  5. Observe that nothing happens. This is not the behavior we want.
  6. In command line, run adb shell input keyevent KEYCODE_ENTER
  7. Observe that we see behavior we want, the search progresses.

So if we have a case of a text field with a Magnifying Glass Enter Key which doesn't progress when the user sends KEYCODE_ENTER, does that mean that there isn't a KeyEventListener for KEYCODE_ENTER on that text field like the Google Search bar must have?

How to Fix?

The fix I came up with (but is not yet tested because I do not have access to code) is that the text field in focus needs to have a KeyEventListener for KEYCODE_ENTER. Is a KeyEventListener the reason why KEYCODE_ENTER may not work? Or should it be listening for KEYCODE_SEARCH?

This question helps confirm my fix theory: detect keyboard search button

Please see the following images for the keys that I'm talking about.

来源:https://stackoverflow.com/questions/39906970/adb-keycodes-fail-to-search-using-android-keyboard-search-key-vs-enter-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!