当前位置: 动力学知识库 > 问答 > 编程问答 >

internet explorer - IE 10 and older - how to identify ctrl left vs right?

问题描述:

Is there any information in the keyUp event fired by IE9/10 that allows to know whether the left or the right ctrl key was released?

Development context: browser "game" where the user says yes (ctrl-right) and no (ctrl-left), handling situations gracefully where user presses both keys by counting last released key.

Findings so far:

  • e.browserEvent.ctrlLeft property is always false on keyUp it seems.
  • e.ctrlKey, e.browserEvent.ctrlKey even seem to be always false on keyUp - for both ctrl keys. (astonishing)
  • e.browserEvent.keyCode is 17 for both left and right.
  • e.originalEvent is undefined.

I can't see how to distinguish left from right in this context. Appreciate any response.

EDIT

Adding to the confusion, in the keyDown events, up to today, I believed that they allow distinguishing ctrlLeft from ctrlRight. There is the property e.browserEvent.ctrlLeft which has the value 'true' when I press the left ctrl key, and 'false' when I press the right ctrl key.

BUT: The situation deteriorates with quick successions of keypresses.

When I press 1. ctrlRight, hold it, then quickly 2. ctrlLeft, things look good: I get two keyDown events. In the first, e.browserEvent.ctrlLeft is false and in the second, e.browserEvent.ctrlLeft is true.

When I press 1. ctrlLeft, hold it, then quickly 2.ctrlRight, not so much: I get two keyDown events. In the first, e.browserEvent.ctrlLeft is true --- in the second, e.browserEvent.ctrlLeft is also true.

MS's documentation states that e.browserEvent.ctrlLeft is the resource to exploit in order to know which ctrl key is pressed.

They provide an interactive demo implementation. However, even in this demo, the faulty behaviour is apparent, producing one state on the first order of keypresses and another on the second order.

https://msdn.microsoft.com/de-de/library/windows/desktop/ms533700

I think I am safe to conclude that there is no way for any client code run by IE<11 to reliably identify which ctrl key has caused any given keyUp event when we come out of the situation that both ctrl keys have been pressed simultaneously.

分享给朋友:
您可能感兴趣的文章:
随机阅读: