Javascript - 带蓝牙键盘的iPad标签键检测 [英] Javascript - iPad Tab Key Detection w/ Bluetooth Keyboard

查看:119
本文介绍了Javascript - 带蓝牙键盘的iPad标签键检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本字段,用户可以在其中键入数据。他们可以使用tab键,然后字段缩进。除了使用蓝牙键盘的ios之外,这种方法效果很好。

I have a text field where users can type data. They can use the tab key and then the field gets indented. This works great on everything except ios with a bluetooth keyboard.

如果我访问 http://www.rapidtables.com/tools/notepad.htm ,我可以在桌面/笔记本电脑上找到标签。但是在我的iPad上......没有骰子。

If I visit http://www.rapidtables.com/tools/notepad.htm, I can tab on my desktop/laptop. But on my iPad... no dice.

如果我访问 https://api.jquery.com/keydown/ https://api.jquery .com / keyup / https://api.jquery.com/keypress/ ...它们中没有人检测到iPad上的标签键。

If I visit https://api.jquery.com/keydown/, https://api.jquery.com/keyup/, https://api.jquery.com/keypress/ ... NONE of them detect the tab key on iPad.

标签键适用于ios本机应用程序,如Notes,并且标签键可以在网页。有没有办法检测Javascript中任何人都知道的Tab键?

The tab key works in ios native applications, like Notes, and the tab key does navigate between fields inside a webpage. Is there a way to detect the tab key in Javascript that anyone knows of?

编辑

这是我拼凑的小提琴,所以你可以看到代码和问题: https:// jsfiddle.net/9jv0bmbx/1/ 基本上我只是检查 e.keyCode === 9 哪个适用于台式机/笔记本电脑。在iPad上,它会记录每个键除了标签键。

Here is a fiddle I threw together so you can see the code and problem in action: https://jsfiddle.net/9jv0bmbx/1/ Basically I am just checking that e.keyCode===9 which works on desktop/laptops. On iPads, it registers EVERY key except the tab key.

推荐答案

EDIT2:

这是解决方案的另一个选项。我发现了一篇关于如何捕获所有事件的文章。下面是一个jsfiddle,这里是我发现这个概念的文章。请注意,在jsfiddle中我返回原始的addEventListener,因为在添加空白侦听器之后您需要完成的操作。

Here is another option for a solution. I found an article that goes over how to capture ALL events. Below is a jsfiddle, and here is the article I found this concept. Note that in the jsfiddle I return the original addEventListener because what you need has been done after adding a blank listener.

jsfiddle

var oldAddEventListener = EventTarget.prototype.addEventListener;

EventTarget.prototype.addEventListener = function(eventName, eventHandler)
{
  oldAddEventListener.call(this, eventName, function(event) {
      if(event.target.id === "textarea" && event.keyCode===9){
        event.preventDefault();
        $(this).val($(this).val()+"\t");
        $("#log").append("<li>Tab Pressed</li>");
      }
    eventHandler(event);
  });
};
$("#textarea").keydown(function(e) {

});

EventTarget.prototype.addEventListener = oldAddEventListener;

编辑:

此处的测试键盘捕获标签keydown。看看这个库,它应该解决你的问题。要么直接使用库,要么通过挖掘代码来弄清楚它如何捕获iOS上的选项卡。
http://dmauro.github.io/Keypress/

The test keyboard here captures the tab keydown. Look into this library, it should fix your issues. Either use the library directly, or figure out how it captures the tab on iOS by digging through the code. http://dmauro.github.io/Keypress/

存在某种硬件/功能键问题,妨碍正常的Tab键按下。按OPTION + Tab会像平常一样触发你的处理程序。也许有某种设置导致了这种情况,但显然您不能指望您的用户更改其设置以使用您的应用。您可以找到一些方法来以某种方式利用它,但看起来这是默认行为,你会坚持使用它。

There is some sort of hardware/function key issue getting in the way of a normal tab key press. Pressing OPTION+Tab will fire your handler like normal. Perhaps there is some sort of setting that is causing this, but obviously you cannot expect your users to change their settings to use your app. You may be able to find some way to leverage this somehow, but it appears that this is the default behavior and you are stuck with it.

有可能检测到iOS设备,并为选项卡的默认行为找出某种覆盖。或者您可以捕获focusOut,或模糊事件并检测它是否不是由鼠标引起的。

It might be possible to detect iOS devices and figure out some sort of override for the tab's default behavior. Or you may be able to capture the focusOut, or blur events and detect if it was not caused by the mouse.

这篇关于Javascript - 带蓝牙键盘的iPad标签键检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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