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

Input on wasm repeats inputs on losing focus #358

Open
NaughtyDog6000 opened this issue Feb 18, 2024 · 0 comments
Open

Input on wasm repeats inputs on losing focus #358

NaughtyDog6000 opened this issue Feb 18, 2024 · 0 comments

Comments

@NaughtyDog6000
Copy link

Bellow is part of the code I use in my project, when Running natively there are no issues with ghost/repeated inputs.

When Running the same logic on wasm, If the user were to lose focus of the application while an input is still being given, that input would be continously fired for every tick/frame until the same key is pressed again.

This happens for me when A key that loads a second page in another tab is pressed and as there is no control for the focus of a new tab, it will always focus the new tab and cause the repetition of the key that was pressed.

    let mut input = INPUT.lock();
    //let bindings = state.ecs.read_resource::<Vec<ActionBinding>>();

    //for btn in input.mouse_button_pressed_set().iter() {
    //    #[cfg(debug_assertions)]
    //    console::log(format!("Mouse Button {} is pressed", btn));
    //}

    // a vec which will store all the keys that the user has inputted on the current tick
    let mut inputted_keys: Vec<String> = Vec::new();

    // itterate of over each of the keys pressed
    for key in input.key_pressed_set().iter() {
        // store the key as a string value for readability in saves/config
        let key_string = format!("{:?}", key);
        console::log(format!("key presed {}", key_string));
        inputted_keys.push(key_string);
    }

    #[cfg(debug_assertions)]
    if inputted_keys.len() > 0 {
        console::log(inputted_keys.join(", "));
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant