Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upFix Keyboard.presses #463
Conversation
jvoigtlaender
referenced this pull request
Dec 18, 2015
Closed
Keyboard.presses emitting '0' for most keys in Firefox #326
jvoigtlaender
referenced this pull request
Jan 6, 2016
Closed
Keyboard.presses not working in Firefox v 42.0 #462
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
referenced this pull request
Feb 8, 2016
Closed
Add keyCode signal for keydown events #500
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
marreman
Feb 21, 2016
Maybe using a polyfill approach is better? Pushing cross-browser concerns to the edges of the code base? Also, they are very easy to remove once all targeted browsers are following standards.
marreman
commented
Feb 21, 2016
|
Maybe using a polyfill approach is better? Pushing cross-browser concerns to the edges of the code base? Also, they are very easy to remove once all targeted browsers are following standards. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Feb 22, 2016
Contributor
@marreman, I'm not sure what exactly you are proposing to do differently. The native Keyboard.js file is pretty much at the edge of the code base. Is your point just to move the one line change there into a separate function that can later be replaced by some more simple projection? Or some more substantial deviation from this specific pull request? (I don't think moving the Signal.filter from Keyboard.elm to some equivalent logic on the .js side would be worth it, but do you have a concrete proposal?)
|
@marreman, I'm not sure what exactly you are proposing to do differently. The native |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
marreman
Feb 22, 2016
After reading more on the subject, I realize that my comment was a bit premature. It is not as easy as I thought. keyCode, which and charCode are all deprecated and key is still just part of a working draft and only implemented in Firefox and IE9+.
I was thinking of something like this in some part of the code base that is dedicated to normalizing browser behavior:
Object.defineProperty(KeyboardEvent.prototype, 'keyCode', {
get: function () {
// make things consistent..
}
});
marreman
commented
Feb 22, 2016
|
After reading more on the subject, I realize that my comment was a bit premature. It is not as easy as I thought. I was thinking of something like this in some part of the code base that is dedicated to normalizing browser behavior:
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Feb 23, 2016
Contributor
I see. If the Elm runtime/core had such a centralized place for normalizing browser behavior, it would be good to handle this case there as well. But that's not how core is structured at the moment. If there is something to polyfill (like requestAnimationFrame), it happens near the use site, not in a centralized place. So the same makes sense to do here. And the specific issue that Firefox fires keypress on non-character keys couldn't be handled with your proposed approach anyway.
So I stand by the existing pull request here.
|
I see. If the Elm runtime/ So I stand by the existing pull request here. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
marreman
Feb 23, 2016
I'm sorry for bothering with ignorant comments. Just very eager to help! +1 for your proposal! :P
marreman
commented
Feb 23, 2016
|
I'm sorry for bothering with ignorant comments. Just very eager to help! +1 for your proposal! :P |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Oh, no problem, and no need to apologize. |
jvoigtlaender
added some commits
Feb 26, 2016
evancz
closed this
Apr 28, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Apr 28, 2016
Member
Things are going to work different in an upcoming release. I think this issue will be less, but if it's not we can pick it back up on the appropriate repo.
|
Things are going to work different in an upcoming release. I think this issue will be less, but if it's not we can pick it back up on the appropriate repo. |
This was referenced May 24, 2016
jvoigtlaender
referenced this pull request
Jun 6, 2016
Closed
Not all key codes work in every browser #3
jvoigtlaender
referenced this pull request
Aug 6, 2016
Closed
Use KeyboardEvent.which instead of KeyboardEvent.keyCode #6
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Aug 6, 2016
Contributor
It turned out that elm-lang/keyboard still has this problem, the issue did not turn out to be less with that release. As said in the previous comment, it should then be picked back up on that repo.
It now has been picked up there, so anybody who happens to come by here, be directed to:
- elm-lang/keyboard#6
- and, related, also: elm-lang/keyboard#5
|
It turned out that It now has been picked up there, so anybody who happens to come by here, be directed to:
|
jvoigtlaender commentedDec 15, 2015
The issue this pull request addresses can be demonstrated with this program (pasteable into http://elm-lang.org/try):
What is expected is that whenever a key is pressed, the corresponding code is printed. But in reality the behavior depends on the browser, and in no browser does it correspond to what the documentation says. In particular,
adon't work, but special keys like the arrows do work,More specifically,
agives code0, while special keys give meaningful codes,agives a meaningful code, while special keys fire no event at all.Error reports related to this have come up again and again. See also https://github.com/elm-lang/core/issues/326, https://github.com/elm-lang/core/issues/427, https://github.com/elm-lang/core/pull/435, https://github.com/elm-lang/core/issues/462, elm/compiler#1069, elm-lang/elm-platform#123, elm/elm-lang.org#440, elm-lang@016d44a.
This pull request here fixes the behavior. Of necessity, it does so in a way that will require a change to the signal's documentation. Because the signal's documentation claims something that is impossible to implement across current browsers, and likely was never true.
The main data and cause for all this is that Firefox and Chrome (and other browsers that behave like Chrome, while I haven't found a browser that behaves like Firefox here) behave quite differently concerning
keydown,keyup, andkeypressevents, as follows:keydownandkeyupwithkeyCodeandwhichset to the same non-zero value, butcharCodeset to zerokeypresswithkeyCodeset to the same non-zero value as above, butwhichandcharCodeset to zerokeydownandkeyupwithkeyCodeandwhichset to the same non-zero value, butcharCodeset to zerokeypresswithwhichandcharCodeset to the same non-zero value, butkeyCodeset to zerokeydownandkeyupwithkeyCodeandwhichset to the same non-zero value, butcharCodeset to zerokeypressat allkeydownandkeyupwithkeyCodeandwhichset to the same non-zero value, butcharCodeset to zerokeypresswithkeyCodeandwhichandcharCodeall set to the same non-zero valueAs a first thing to note, it will be impossible to let
Signal.keypresshave an event for arrow keys in Chrome. And Chrome is in its rights here, because that's how the specification says it should be. See https://developer.mozilla.org/en-US/docs/Web/Events/keypress, which says: "... is fired when a key is pressed down and that key normally produces a character value". So the only way to get consistent behavior across browsers here is to stop (Keyboard.pressesin) Firefox from giving codes like38for up-arrow.As a second thing to note, using
keyCodeto detect which key was pressed (as is currently done) will not work in Firefox for character keys. By looking at the above analysis, it would be okay (for the two browsers above) to simply usewhich, because it contains the right thing in all situations. One could be concerned, though, about historical or other browsers. So, to be on the safe side, I have used what jQuery uses. That is battle tested. And wheneverwhichis defined (which is as far as I can tell always the case), it is equivalent to simply usingwhichright away.I don't see any reasonable alternatives to either using
whichor what jQuery uses. In particular, I don't think it makes sense to strive for a solution that "does not change anything of the existing behavior". As demonstrated above, there is no well-defined "existing behavior" at the moment, and probably never was.