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

[rcore] Inconsistency in the API between GetGamepadButtonPressed() and GetKeyPressed() #4007

Open
4 tasks done
bohonghuang opened this issue May 26, 2024 · 3 comments
Open
4 tasks done

Comments

@bohonghuang
Copy link
Contributor

bohonghuang commented May 26, 2024

Please, before submitting a new issue verify and check:

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

Hello, I have been trying to use the gamepad input support in Raylib and have noticed that GetGamepadButtonPressed doesn't seem to work as expected. It always returns the previously pressed button instead of maintaining a key queue like GetKeyPressed, where each call retrieves one key from the queue. However, I have found that this behavior is consistent across all backends, not just GLFW. Is this behavior by design? If it is, it might be worth considering the consistency between APIs. For example, making some distinctions in the naming could be beneficial for clarity and consistency.

@raysan5
Copy link
Owner

raysan5 commented May 29, 2024

@bohonghuang Actually that's the original implementation for Gamepad and it also was for Keys, some years after that the keys queue was added for convenience. Simply, noone had that requirement before for gamepad. Do you need it for some specific use-case or is it only for library consistency reasons?

@bohonghuang
Copy link
Contributor Author

bohonghuang commented May 29, 2024

@bohonghuang Actually that's the original implementation for Gamepad and it also was for Keys, some years after that the keys queue was added for convenience. Simply, noone had that requirement before for gamepad. Do you need it for some specific use-case or is it only for library consistency reasons?

Sure, I want my game to support both gamepad and keyboard controls simultaneously, but I've encountered issues when trying to handle gamepad and keyboard inputs using the same logic. IMO, the current GetGamepadButtonPressed has limited applications because it always returns the last pressed button, so that I can hardly find its use case:

  1. For UI interaction inputs, we usually expect a button press to be triggered only once. I frequently use GetKeyPressed and occasionally use IsKeyPressed.
  2. For gameplay inputs, we usually check whether a specific button is being pressed directly. I use IsKeyDown for keyboard inputs.

@raysan5
Copy link
Owner

raysan5 commented May 29, 2024

@bohonghuang As per my understanding, supporting gamepad button queue shouldn't break any existing code base, just add some extra internal functionality, feel free to send a PR, but it is a core functional cange and it should be tested on all supported platforms

@raysan5 raysan5 changed the title [rcore] Inconsistency in the API between GetGamepadButtonPressed and GetKeyPressed [rcore] Inconsistency in the API between GetGamepadButtonPressed() and GetKeyPressed() Jun 28, 2024
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

2 participants