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

Key presses get repeated #523

Closed
42triangles opened this issue Aug 2, 2019 · 4 comments
Closed

Key presses get repeated #523

42triangles opened this issue Aug 2, 2019 · 4 comments
Labels
bug Some API breaks the contract it establishes documentation-hard Documentation on specific structures, functions, etc subsystem-input
Milestone

Comments

@42triangles
Copy link

42triangles commented Aug 2, 2019

Describe the bug
The documentation for ButtonState::Pressed states that it only gets triggered, if they key was pressed in this frame. However, after a slight delay with the button still being held, this events gets spammed. (like in a text field when pressing a button long enough)

So this is either an implementation bug, or a documentation mistake (in which case it would make sense to provide a way to disable key repetition).

To Reproduce

use quicksilver::{geom::Vector, input::ButtonState, lifecycle::{Event, State, Window, run}, Result};

struct App;

impl State for App {
    fn new() -> Result<Self> {
        Ok(App)
    }

    fn event(&mut self, event: &Event, _: &mut Window) -> Result<()> {
        match event {
            Event::Key(_, ButtonState::Pressed) => println!("pressed"),
            _ => (),
        }

        Ok(())
    }
}

fn main() {
    run::<App>("Test", Vector::new(640, 480), Default::default());
}

Environment and versions (please complete the following information):

  • Environment: Arch Linux under i3
  • Rust compiler version: 1.37.0-nightly (991c719a1 2019-06-08)
  • Quicksilver verison: 0.3.18
@ryanisaacg
Copy link
Owner

That's a doc error, ButtonState::Pressed occurs once in the key state, not the events (so exactly one update will execute where window.keyboard()[MyKey] is equal to ButtonState::Pressed). Probably a good option is to use a different enum from ButtonState in the events.

Do key repeats for events interfere with your use-case?

@ryanisaacg ryanisaacg added bug Some API breaks the contract it establishes documentation-hard Documentation on specific structures, functions, etc subsystem-input labels Aug 5, 2019
@42triangles
Copy link
Author

They do, since jumping in my game reacts to starting the button press (starting the jump), and letting go (falling straight down).

The workaround I then used was keeping track of whether or not the button was already released, which honestly feels kind of hacky.

@ryanisaacg ryanisaacg added this to the Async API milestone Sep 1, 2019
@ryanisaacg
Copy link
Owner

I'm going to be re-working the lifecycle system for async / await, so I'll catch repeated keypresses in the new design.

@ryanisaacg
Copy link
Owner

The new (0.4.x) API doesn't differentiate between 'this key is held down' and 'this key has just been pressed;' the way to do that now is to simply listen for key events. That should resolve this issue going forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Some API breaks the contract it establishes documentation-hard Documentation on specific structures, functions, etc subsystem-input
Projects
None yet
Development

No branches or pull requests

2 participants