-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
Repeated key press events #1220
Comments
Gist with |
This is super annoying and proving harder to fix than I thought. Please fix this. Press and release events should behave as such. Only call them once for every event. |
Separating the events would be cleaner. You can also test with the "user_input" example: https://github.com/PistonDevelopers/piston-examples/tree/master/user_input We need a solution that is consistent across window backends. |
I've done some investigation: This is an issue with the Glutin backend only. The SDL2 and GLFW backends emits key presses once. Piston uses "text" events for text editor behavior, which includes repeats. Key presses (not "text" events) should therefore only be emitted once in Piston. No design changes are needed in the Piston core. The reason this bug appears in the Glutin backend is an issue with the Glutin API. Currently, it is not possible to tell the difference between key presses and key repeats in Glutin without using heuristics. This might make it problematic to fix in the backend. The current state of this issue in Glutin/Winit is a proposal to change the API. Related issues (Glutin and Winit): |
A heuristic solution to fix the behavior in the Glutin backend could use a |
I was having the same problem and found this issue. |
A common workaround is to store a state whether a button is pressed or not. For example, in 2D platform games it is common to use a vector to represent the state of up/down/right/left and all game logic depends on this state instead of button presses directly. A less common workaround is to fork the Glutin backend in Piston and make the modifications for a specific project. These kinds of problems is one of reasons Piston uses a modular architecture. I believe the issue was delayed because a fix in Glutin was expected. This needs careful analysis because platforms where key release behavior is different might enter a state where some button is believed to pressed when it is in fact released. I tested this on "user_input" on OSX 10.11.6 and found the following:
Redundant release events do not usually cause problems and we have not determined yet the best behavior for key released in combination with window unfocus events. So, I think we should focus on press events. One idea is to use the most straightforward method suggested by PistonDevelopers/glutin_window#183 and recommend the less common workaround (forking the Glutin backend) for people who experience problems on custom platforms. |
Closed by PistonDevelopers/glutin_window#201 |
Holding down a key in Piston will begin to generate multiple spurious input events after short delay. This behaviour is like the common "key repeat" feature found in most text areas in GUIs, but is presumably only accidentally happening in Piston, given that it makes it impossible to tell which are the actual press events, and which are repeats. (And previous discussion also suggests it is not deliberate — see below.)
Observed on Mac OS X latest (10.13.2) and previous versions. Not sure if this affects other platforms. Not sure if it's caused by Piston itself, or some underlying input library. Maybe it only shows up on some backends.
Code
How to reproduce
Just hold down any key, and watch the terminal output.
Output
Previous discussion
In a previous discussion somebody believed that they'd seen key repeat behaviour in Piston, then later concluded that they were thinking of some other library.
And later...
And from someone else...
This combined with the evidence above makes me suspect it may be a platform- or backend-specific bug. I'll try on another OS and post results here.
The text was updated successfully, but these errors were encountered: