alt has odd behavior
optikalefx opened this issue · 5 comments
using this code
@on(keyUp('alt'))
toggleClientSku() {
}
never fires.
Using @on(keyUp('alt+KeyS'))
Fires, randomly. I hit the key combo 10 times once a second and this was the result.
if I use @on(keyUp('KeyS'))
.
It works perfectly with no issues.
Here is a twiddle with just 'alt' which doesn't fire at all in console. https://ember-twiddle.com/0854fae37ace124668eac3fc141a6431?openFiles=controllers.application.js%2C
If you change this to KeyS
it works. If you change to alt+KeyS
it fires randomly.
If you want alt to fire on its own, you should use AltLeft
. The modifier keys (+alt
, +cmd
, +shift
, etc) don't reference specific keys (such as ShiftLeft
or ShiftRight
), but instead will activate when any shift key is held down. You can find a reference to the valid codes here.
As for the spotty pickup of alt+KeyS
, are you holding alt
down the whole time, or releasing them simultaneously? If it's simultaneous, it's likely a timing issue, where the keyup for KeyS
fires after you've already released alt.
Super interesting. So I was releasing both at the same time. Which is the problem. If I hold alt the whole time and just keep tapping s
then it's fine.
I wonder if that's correct. I watched 5 people just now hit a similar thing, cmd + c
for copy, And everyone did the release bit. What would it take to implement such a thing?
Right now we determine if a modifier key is being held by looking at the key event. This is simply utilizing a native feature of the browser. If we wanted to see if a key has been released in the last few milliseconds, then we'd have to keep a log of what keys were recently pressed and then check against that as well as the actual event.
FWIW it seems that AltLeft
also doesn't work quite as expected.
onAltKey: on(keyUp('AltLeft'), keyDown('AltLeft'), function(evt) {
console.log(evt.altKey);
}),
for the snippet above when I press the Alt key, I get six console logs when I release the key again, and they all show false
. I would expect there to be preferably one output with true
when pressed, and false
when released.
the snippet below seems to work correctly though:
onAltKey: on(keyUp(), keyDown(), function(evt) {
console.log(evt.altKey);
}),
Closing for lack of activity. It would great to review master for unexpected behavior around these topics as we've changed the key matching logic substantially.