raysan5 / raylib

A simple and easy-to-use library to enjoy videogames programming
http://www.raylib.com
zlib License
21.55k stars 2.18k forks source link

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

Open bohonghuang opened 3 months ago

bohonghuang commented 3 months ago

Please, before submitting a new issue verify and check:

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 commented 3 months ago

@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 commented 3 months ago

@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 commented 3 months ago

@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 change and it should be tested on all supported platforms

raysan5 commented 3 weeks ago

@bohonghuang Did you review this issue? Are you sending a PR?

bohonghuang commented 3 weeks ago

@bohonghuang Did you review this issue? Are you sending a PR?

I'm afraid I may not be able to work on this issue right now because I'm on a work trip and lack both a gamepad and multiple platforms for testing. If you find this issue bothersome, feel free to close it. I might submit a PR later.