"Next"的键码是什么?在android virtualKeyBoard中 [英] What is the keycode for "Next" in android virtualKeyBoard

查看:34
本文介绍了"Next"的键码是什么?在android virtualKeyBoard中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在增强(按角度指示),如果未选择任何选项,谷歌放置自动完成输入以选择第一个选项.

I am enhancing (in an angular directive) the google places autocomplete input to select the first option if none is selected.

我正在使用下面的代码,当使用"tab"或"enter"键时,它就像一个超级按钮.

I am using the below code, which works like a charm when using "tab" or "enter" key.

不幸的是,它不能在带有 virtualkeyboard"next" key ...

Unfortunatly it is not working on android device (chrome) whith virtualkeyboard "next" key...

此"下一个"键的键代码可能是什么,因为它既不是"tab"键(9)也不是"enter"键(13)

What could be the KeyCode of this "next" key as it is neither "tab" (9) or "enter" (13)

selectFirstOnEnterOrTab(input) {
    // prevent submit on enter (13)
    $(input).keydown(function (e) {
      if (e.which === 13 && $('.pac-container:visible').length) {
        return false;
      }
    });

    // store the original event binding function
    const _addEventListener = (input.addEventListener) ? input.addEventListener : input.attachEvent;
    function addEventListenerWrapper(type, listener) {
      // Simulate a 'down arrow' keypress on hitting 'return' when no pac suggestion is selected,
      // and then trigger the original listener.
      if (type === 'keydown') {
        const orig_listener = listener;
        listener = function (event) {
          const suggestion_selected = $('.pac-item-selected').length > 0;
          if ((event.which >= 9 && event.which <= 13) && !suggestion_selected) {
            const simulated_downarrow = $.Event('keydown', {
              keyCode: 40, which: 40
            });
            orig_listener.apply(input, [simulated_downarrow]);
          }
          orig_listener.apply(input, [event]);
        };
      }
      _addEventListener.apply(input, [type, listener]); // add the modified listener
    }
    if (input.addEventListener) {
      input.addEventListener = addEventListenerWrapper;
    } else if (input.attachEvent) {
      input.attachEvent = addEventListenerWrapper;
    }
  }

编辑

按照Pitto的建议,我已经在Android设备上记录了哪些代码和键码,对于我按下的所有键,我都收到229,这显然是android的正常行为.关于如何更新代码以使其也可以在Android设备上运行的任何想法...

Following Pitto suggestion, I have logged which and keycode on my android device, and for all the key I press, I receive 229, which apparently is a normal behaviour for android. Any ideas on how I can update my code for it to work on Android device too...

EDIT2

在android上,在按下"next"时,没有触发 keydown 事件

On android, on "next" pressed, there is no keydown event fired

推荐答案

正如已经指出的那样, e.which / e.keyCode 的值将为 229 e.key 将是'Unidentified'.您可以使用 https://keyjs.dev 进行检查,并在其中找到有关虚拟/移动键盘的说明:

As pointed out already, the value for e.which / e.keyCode is going to be 229 and e.key is going to be 'Unidentified'. You can check that using https://keyjs.dev, where you will also find an explanation about virtual/mobile keyboards:

在使用虚拟/移动键盘(正式称为IME(输入法编辑器))时,W3C标准规定KeyboardEvent的e.keyCode应该为229,而e.key应该为"Unidentified".

When using virtual/mobile keyboards, formally know as IME (Input-Method Editor), the W3C standard states that a KeyboardEvent's e.keyCode should be 229 and e.key should be "Unidentified".

移动设备上最好的选择可能是在下拉菜单中添加一个展开/向下箭头,并让用户根据需要手动打开它.

The best option on mobile is probably just adding an expand/down arrow to the dropdown and let users open it manually if they want to.

这篇关于"Next"的键码是什么?在android virtualKeyBoard中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆