Keycode is always zero in Chrome for Android

后端 未结 10 2064
栀梦
栀梦 2020-12-05 13:17

I need to detect the keycode for a custom search box on my website, but the keycode always returns as zero on Chrome for Android (except for backspace, which returns 8). Has

10条回答
  •  独厮守ぢ
    2020-12-05 13:52

    I faced this issue and this is how I figured out how to solve the problem.

    • First, you need to enable USB debugging onto your Android phone so you can see the logs of your browser on your desktop machine.
    • Second, refresh your web app on your phone and inside your console on the desktop type "monitorEvents(document)" or whatever element you want to inspect.
    • Do the action you want to inspect on your phone.

    And this is how I found that the keydown event was actually fired by a unique event called "textInput" which contains the information inside event.originalEvent.data.

    Hope this saves you time and good luck!

提交回复
热议问题