key repeat -- how to turn this off? #3373
-
I am speaking of the ElementState module. For example, There are many issues opened up requesting this feature dating from years back. I don't think it's worth it for anybody (including myself) to spend, for example, 30 minutes browsing through all of what there is to find on this topic just to get a simple "no" or "yes, here is how it is done." So, let's keep this discussion simple. How do you turn off key repeat? Let's keep our answers short. This will help us all find out what we need without digging through long threads. I'll mention this to try and be helpful to other people -- if it is impossible, then it is not too hard just to make a variable such as "was_up_key_press_counter" and reset it to 0 when the key is released. This is only one of many possible workarounds. EDIT: Going to give some honest feedback, if there truely is no way to detect or turn off key repeat, then I think winit should probably get there stuff together because this is such an obvious and needed feature 😉 It makes me think that the people who made this library have not actually used it to make real programs, or the programs they make are very narrow in type (I am making a game with a custom engine, so that is my perspective), and they don't actually have any idea what their product needs to do to be functional. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 42 replies
-
https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.repeat
I'd suggest you to learn how to communicate, We don't owe you anything, we're working on it in our free time for nothing. It's not the first time you communicate and try to straight offense people. |
Beta Was this translation helpful? Give feedback.
-
There's a legit question here. I found this because I have a problem where holding an arrow key down for a long time in a game-type program sometimes causes the action to continue for seconds after key release. I'm ignoring events where input.repeat is set. But I'm not sure that's the correct action. Could that cause me to miss a key-up event? |
Beta Was this translation helpful? Give feedback.
-
Sorry, I meant that I render at RedrawRequested, but I call RequestRedraw only at AboutToWait. Winit docs say to call RequestRedraw at the end of the redraw in RedrawRequested, but that behaves terribly. Worst case is Windows executables under Wine, where every key is delayed about 3 seconds. X11 on Linux is a big sluggish. Winit doesn't really manage this; it passes the buck to the underlying platform. Wine has its own event loop, and it's not a good one. |
Beta Was this translation helpful? Give feedback.
-
I'd appreciate that. I'm seeing this in a full-scale game, with the whole Winit/egui/rend3/Vulkan stack running. |
Beta Was this translation helpful? Give feedback.
-
Well, the story is more interesting than I thought. My idea of making a simple app to show the repeat keys buffering didn't work -- or rather the app did work in that it didn't have a problem with buffering. That made me go back to my app that had the issue (this was back in git history of an app a couple months back which I had since converted to using device events). At the time the app was based on winit 0.29.15. I can confirm that window events for this app cause buffering of repeat keys while device events do not. This is on x11. But when I change from FIFO to Immediate presentation mode the issue goes away (I render at 30 fps in FIFO on this monitor). After putting in some print lines there was consistently only 1 repeat key event per frame. Not sure of the reason for this. Even when I increased the repeat rate to be only 1 ms between repeats I only got one repeat key per frame (in FIFO). This might be because I'm spending so much time waiting on vsync, which is what krill suggested. That being said, none of this happens on wayland. Even with 40 fps vsync (different machine) and 1 ms per repeat key I did not see any buffering of repeat keys. This makes me think there is something a little funky with x11 and that this isn't just an effect of vsync (or slow render times). So anyway, I don't think the repeat key buffering is good behavior, but I'm not sure what winit can do about it. My work around is to use WindowEvent::KeyInput events for everything but X11, where I'll use DeviceEventK::Key (for key presses, not text input). One thing I'm curious about is whether some of this can be ameliorated by timing the render call closer to vsync. That's an advanced technique that shouldn't be required (in my view)to get decent key repeat behavior, but it would at least be a solution. I don't think rendering in a thread solves the issue because in the end it's waiting for vsync that is the issue, and that has to happen in the main thread as far as I know. Oh, and I guess you can always turn off or down key repeat in the settings and advise x11 users to do the same. |
Beta Was this translation helpful? Give feedback.
-
@cfagot I need to get to this. Thanks. We need to figure out what best practice for games is. |
Beta Was this translation helpful? Give feedback.
https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.repeat
I'd suggest you to learn how to communicate, We don't owe you anything, we're working on it in our free time for nothing. It's not the first time you communicate and try to straight offense people.