-
Notifications
You must be signed in to change notification settings - Fork 125
Open
Description
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(", "));
}Metadata
Metadata
Assignees
Labels
No labels