raysan5 / raylib

A simple and easy-to-use library to enjoy videogames programming

Home Page:http://www.raylib.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

bohonghuang opened this issue · comments

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.

commented

@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 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.
commented

@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