Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyboardDragListener: How should multiple pressed direction keys behave? #1655

Closed
zepumph opened this issue Sep 5, 2024 · 6 comments
Closed

Comments

@zepumph
Copy link
Member

zepumph commented Sep 5, 2024

While testing for phetsims/scenery-phet#869, I was surprised to see that if I alternate pressing left and right arrow keys, but make sure that the old one stays down until well after the new one is pressed, I was surprised to see that the new one doesn't take precedent. @jessegreenberg does this seem like reasonable behavior to you? Are you aware of this issue and I'm just late to the party?

We should decide mostly if this blocks Buoyancy. Adding to the project board.

@jessegreenberg
Copy link
Contributor

Yes, this seems reasonable to me. I have observed the same behavior in other 2d games I have played. The behavior comes from this bit in KeyboardDragListener, the delta is just a sum from the pressed keys.

private moveFromDelta( delta: number ): void {
let deltaX = 0;
let deltaY = 0;
if ( this.leftKeyDownProperty.value ) {
deltaX -= delta;
}
if ( this.rightKeyDownProperty.value ) {
deltaX += delta;
}
if ( this.upKeyDownProperty.value ) {
deltaY -= delta;
}
if ( this.downKeyDownProperty.value ) {
deltaY += delta;
}

@zepumph
Copy link
Member Author

zepumph commented Sep 9, 2024

I like that design! Makes sense and I just wanted to double check since it is different from native browser key event behavior.

the delta is just a sum from the pressed keys.

This is not always the exact behavior I see. In buoyancy, when dragging a block, if I hold both left/right keys, the block correctly stays still, but when I then add up arrow the block buggily stays still. This doesn't happen when I add the down arrown as the third key, in which the block does correctly (given the spec above) move down.

@zepumph zepumph assigned jessegreenberg and unassigned zepumph Sep 9, 2024
@jessegreenberg
Copy link
Contributor

I see, thanks - I can reproduce that for the arrow keys but not the WASD keys. That is a bug, Ill take a look.

@zepumph zepumph changed the title KeyboardDragListener: new opposite key doesn't take priority when dragging in multiple directions. KeyboardDragListener: How should multiple pressed direction keys behave? Sep 9, 2024
@jessegreenberg
Copy link
Contributor

So it turns out this is actually happening at the hardware level and is called "key ghosting". I was alerted because we don't even get the DOM event in BrowserEvents. But you can see it really clearly happening here (and for other combinations too).

https://www.microsoft.com/applied-sciences/projects/anti-ghosting-demo

I am afraid the best we can do is document this so it isn't a surprise next time.

jessegreenberg added a commit that referenced this issue Sep 9, 2024
@jessegreenberg
Copy link
Contributor

I added a line of documentation. @zepumph seem OK or do you think it would be better somewhere else?

@zepumph
Copy link
Member Author

zepumph commented Sep 9, 2024

Very cool! Thanks

@zepumph zepumph closed this as completed Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants