English 中文(简体)
如何区分 Java文中的出入境和回归钥匙?
原标题:How to differentiate between Enter and Return keys in Javascript?

一些台式镜子对运输回流钥匙进行处理,金垫子进入钥匙不同。 我注意到,这两条钥匙在Javascript (jQuery)中产生了相同的关键概念(13)。

它们是否在浏览器环境中被转换为平等,或者是否有可能区分(例如,使捷克共和国在案文领域形成新的一线,而进入钥匙将其形式)?

最佳回答

见Jan Wolters' treatmentise on 。 Java 马德:主板活动

<代码>Enter和Numpadenter都给出了相同的关键编码,即13条,因为浏览器没有区分两个钥匙。 诚实,也不大环境。 可以通过视窗软件(例如)对二者进行区分,但确实为此做出了额外努力。 然而,这不属于浏览器的抽象范围。

UPDATE

As Bill Thorne rightally mentions, the Key板Event Object Sports a place property nowadays.

https://developer.mozilla.org/en-US/docs/Web/API/Key板Event/position”rel=“noreferer” 计算机网络:

可能的价值是:

DOM_KEY_LOCATION_STANDARD 0 The key has only one version, or can t be distinguished between the left and right versions of the key, and was not pressed on the numeric keypad or a key that is considered to be part of the keypad.

DOM_KEY_LOCATION_LEFT 1 The key was the left-hand version of the key; for example, the left-hand Control key was pressed on a standard 101 key US keyboard. This value is only used for keys that have more that one possible location on the keyboard.

DOM_KEY_LOCATION_RIGHT 2 The key was the right-hand version of the key; for example, the right-hand Control key is pressed on a standard 101 key US keyboard. This value is only used for keys that have more that one possible location on the keyboard.

DOM_KEY_LOCATION_NUMPAD 3 The key was on the numeric keypad, or has a virtual key code that corresponds to the numeric keypad.

Note: When NumLock is locked, Gecko always returns DOM_KEY_LOCATION_NUMPAD for the keys on the numeric pad. Otherwise, when NumLock is unlocked and the keyboard actually has a numeric keypad, Gecko always returns DOM_KEY_LOCATION_NUMPAD too. On the other hand, if the keyboard doesn t have a keypad, such as on a notebook computer, some keys become Numpad only when NumLock is locked. When such keys fires key events, the location attribute value depends on the key. That is, it must not be DOM_KEY_LOCATION_NUMPAD. Note: NumLock key s key events indicate DOM_KEY_LOCATION_STANDARD both on Gecko and Internet Explorer.

问题回答

如果在钥匙板上存在实际不同的关键,浏览器应用应当与桌面应用一样能够加以区别。

最新版本的 Chrome(39.0.2171.95米)、Em(2.32.0.3)、IE(11.0.9600.17501)和Series(12.17)的主角现在有所在地财产。 我将假定这种财产已经存在一段时间,尽管有很强的记录。

on子的测试显示,当“热”进入钥匙时,关键Code=13和地点=0;当金稻进入时,关键Code=13和地点=3。

So the following code can be used to set key==13 if the enter, key==176 if numpad enter:

window.onkeydown=function(ev)
{
    var e= ev || window.event,
      key = e.keyCode || e.which;

    if ((key==13) &&
        (e.location===3))
      key=176; // 176 is the scancode for the numpad enter
    // continued....
}

我正在提供最新情况,因为这个问题仍然出现在山洞搜索结果的顶端。

Per MDN, Key板Event.keyCode<<>

KeyboardEvent keys can be determined by accessing the KeyboardEvent.key, KeyboardEvent.code, and KeyboardEvent.location properties as necessary.

<代码>Key板Event.key回报率,一般见于产出钥匙的文本编辑,非产出钥匙的名称(包括个案敏感)。

KeyboardEvent.code returns a string description of the key.

了解这些特性之间的区别有助于确定哪些内容最适合您的具体情况。 就本问题而言:event.key将交还同一产出(“Enter”),而event.code将分别交还<>Enter”和>NumpadEnter”

在这种情况下,如果你想要区分南板和键盘,你可以使用<代码>event.code。 如果您希望其运行相同,event.key。 这将是更好的选择。

If you wanted to differentiate between other keys, such as the left and right Ctrl keys, you would also want to look at the event.location property.

I m 添加一个小型板块活动场,看看这些活动特性之间的区别。 MDN href=“https://jsfiddle.net/api/mdn/” rel=“noreferer”概念,我仅稍作改动:

window.addEventListener("keydown", function(event) {

  let str = "key =  " + event.key + 
              "  &nbsp code =  " + event.code + " " + 
              "  &nbsp location =  " + event.location + " " ;
              
  let el = document.createElement("span");
  
  el.innerHTML = str + "<br/>";
 
  document.getElementById("output").appendChild(el);
  
}, true);
#output {
  font-family: Arial, Helvetica, sans-serif;
  overflow-y: auto;
  margin-left: 4em
}

#output span {
  line-height: 2em;
}

#output :nth-child(2n) {
  color: blue;
}
<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code -->

<p>
  Press keys on the keyboard to see what the KeyboardEvent s key and code values are for  each one.
</p>
<div id="output"></div>

可通过<代码>代码对活动财产加以区分。 表格一的复标:NumpadEnter,另一封填表。 见。 或者,你也可以使用<条码>><>分立>/编码>所有情况下都使用的财产,而不同的是<条码><>代码>。 升温3,而其他填入则返回0。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签