Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

just_pressed does not work correctly #7

Closed
dis-da-moe opened this issue Jun 5, 2022 · 3 comments
Closed

just_pressed does not work correctly #7

dis-da-moe opened this issue Jun 5, 2022 · 3 comments

Comments

@dis-da-moe
Copy link

How to reproduce:

  1. Copy the setup from examples/singleplayer.rs
  2. Replace the code in check_input with this
use EnumeratedBinding::*;
use EnumeratedMovementBinding::*;

if let Some(vertical) = query.single().axis(&Movement(Vertical)).first() {
    if vertical.press.just_pressed() {
        println!("just pressed");
    }
}

Issues:

  1. This code will print "just pressed" more than once when a key for the Vertical axis is pressed.
  2. If the key is held down and auto-repeat is enabled in the OS (it's enabled for me in Windows 10) it will print every frame once auto-repeat starts.

I believe that 1. is caused by using a fixed value of 75ms in src/press_state.rs instead of something like deltaTime

// just_pressed
if let Some(instant) = started_pressing_instant {
    instant.elapsed().as_millis() <= 75
} else {
    true
}

but I don't know what would cause 2. (the auto-repeat issue)

@axyiee
Copy link
Owner

axyiee commented Jun 5, 2022

Can you explain more about this 'auto-repeat' feature? I don't have Windows installed on my machine and I didn't find much information about this on the internet. The issue with the just_press should now be fixed in the commit above.

axyiee added a commit that referenced this issue Jun 5, 2022
fix: change fixed time to 1 millisecond in just pressed check (#7)
@dis-da-moe
Copy link
Author

Hi it's just called Windows keyboard repeat, and if you hold down a key it will repeat the key presses, in bevy these key repeats don't count for just_pressed but they do count as just_pressed here

@axyiee
Copy link
Owner

axyiee commented Jun 5, 2022

Fixed by af574f5

@axyiee axyiee closed this as completed Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants