Repository navigation
Replies: 2 comments 2 replies
|
Your mouse is fine, and so is your Linux setup. The mismatch is that on desktop raylib does not translate mouse button numbers at all. It stores whatever index GLFW hands it, straight into the button state array: // src/platforms/rcore_desktop_glfw.c
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
{
CORE.Input.Mouse.currentButtonState[button] = action;
...
}That Meanwhile raylib's enum labels those same slots differently: MOUSE_BUTTON_LEFT = 0,
MOUSE_BUTTON_RIGHT = 1,
MOUSE_BUTTON_MIDDLE = 2,
MOUSE_BUTTON_SIDE = 3, // your back button lands here
MOUSE_BUTTON_EXTRA = 4,
MOUSE_BUTTON_FORWARD = 5,
MOUSE_BUTTON_BACK = 6, // nothing on desktop ever reports thisSo index 3 is exactly where your back button is supposed to arrive. The names SIDE, EXTRA, FORWARD and BACK are just labels for slots 3 to 6. They are not a mapping that anything on the desktop backend performs, and So yes, you can use it reliably, but bind by index rather than by the semantic name. Either use the numeric value or define your own alias so the intent stays readable: #define MY_MOUSE_BACK MOUSE_BUTTON_SIDE // 3
#define MY_MOUSE_FORWARD MOUSE_BUTTON_EXTRA // 4
if (IsMouseButtonPressed(MY_MOUSE_BACK)) { ... }Worth keeping in mind that which physical button sits at 3 versus 4 is decided by the device and the platform, not by raylib, so if you ship this it is best exposed as a rebindable control rather than hardcoded. Your |
|
Following up on this, because I went and checked the other backends and the answer to "can I rely on index 3" turns out to be more interesting than I made it sound. Short version: yes on the two backends you are likely to build against, and there is one where it is actively wrong. GLFW, the default desktop backend, stores the raw GLFW index, as above. Your back button arrives at 3. SDL ( // NOTE: SDL2 mouse button order is LEFT, MIDDLE, RIGHT, but raylib uses LEFT, RIGHT, MIDDLE like GLFW
// The following conditions align SDL with raylib.h MouseButton enum order
int btn = event.button.button - 1;
if (btn == 2) btn = 1;
else if (btn == 1) btn = 2;
RGFW ( int btn = e->button.value;
if (btn == RGFW_mouseLeft) btn = 1;
else if (btn == RGFW_mouseRight) btn = 2;
else if (btn == RGFW_mouseMiddle) btn = 3;
CORE.Input.Mouse.currentButtonState[btn - 1] = 1;Only three values get remapped. Anything else falls through with RGFW_mouseLeft = 0,
RGFW_mouseMiddle, // 1
RGFW_mouseRight, // 2
RGFW_mouseMisc1, RGFW_mouseMisc2, RGFW_mouseMisc3, RGFW_mouseMisc4, RGFW_mouseMisc5, // 3..7So the three named buttons land correctly on 0, 1 and 2, but On X11 that is reachable with exactly the hardware you are describing. RGFW's X11 path maps unrecognised buttons with Nothing overflows, since the highest index reachable is 6 and I have derived this from the source rather than run it, so worth confirming on your setup before filing, but if it does reproduce it is worth an issue against RGFW input mapping. Your For your actual code nothing changes. Bind index 3 for back, keep it rebindable, and you are correct on GLFW and SDL. If this has cleared up the original question, marking it as the answer would be useful, since the enum naming catches people out fairly regularly and this thread now has the backend comparison in one place. |
Uh oh!
There was an error while loading. Please reload this page.
I have an issue using IsMouseButtonPressed() with raylib.
I try checking the buttons, and the mouse back button is of index 3 instead of the index 6 in MouseButton enum.
I am trying to understand what the is. Is it my Linux machine that is not correctly map my mouse ? Does it mean that I cannot use IsMouseButtonPressed() reliably for mouse extra buttons?
Thanks !
All reactions