# Problem with analog stick on Linux

**URL:** <https://discourse.libsdl.org/t/problem-with-analog-stick-on-linux/24197>\
**Category:** SDL Development\
**Created:** [April 11, 2018, 9:28am UTC](https://discourse.libsdl.org/t/problem-with-analog-stick-on-linux/24197 "2018-04-11T09:28:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![franck](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/7ba0ec/32.png) [@franck](https://discourse.libsdl.org/u/franck)\
**Post date:** [April 11, 2018, 9:28am UTC](https://discourse.libsdl.org/t/problem-with-analog-stick-on-linux/24197/1 "2018-04-11T09:28:06Z")

</div>

Hello,  
I’m having [a bug report](https://github.com/Javanaise/mrboom-libretro/issues/33) with the analog stick [from this code.](https://github.com/Javanaise/mrboom-libretro/blob/master/sdl2/sdl2.cpp#L481)  
I can’t test it since I don’t have a joystick with an analog stick, could anyone help me on that and tell me if there is something obviously wrong with this code ?  
Thanks…

---

<div class="post-metadata">

**Author:** ![es5804](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@es5804](https://discourse.libsdl.org/u/es5804)\
**Post date:** [April 12, 2018, 12:26pm UTC](https://discourse.libsdl.org/t/problem-with-analog-stick-on-linux/24197/2 "2018-04-12T12:26:24Z")

</div>

If the player moves the joystick really fast from left to right (or right to left) or if he does left-\>up-\>right then you might not get any event with value in the deadzone. This means that both `button_left` and `button_right` have a value of 1 at the same time.  
To fix this you need to reset the opposite direction like you did with hat motion event:

```
if ((e.jaxis.axis == 0) || (e.jaxis.axis == 2))
     {
        if ((axis[0] == 1) || (axis[2] == 1))
        {
           mrboom_update_input(button_right, getPlayerFromJoystickPort(e.jaxis.which), 1, false);
           mrboom_update_input(button_left, getPlayerFromJoystickPort(e.jaxis.which), 0, false);
        }
        else if ((axis[0] == -1) || (axis[2] == -1))
        {
           mrboom_update_input(button_left, getPlayerFromJoystickPort(e.jaxis.which), 1, false);
           mrboom_update_input(button_right, getPlayerFromJoystickPort(e.jaxis.which), 0, false);
        }
        else
        {
           mrboom_update_input(button_left, getPlayerFromJoystickPort(e.jaxis.which), 0, false);
           mrboom_update_input(button_right, getPlayerFromJoystickPort(e.jaxis.which), 0, false);
        }
}

```

and the same thing for up and down.

Also, with a xbox controller on Linux, axis `2` is the left trigger which has a rest position of -32767. So if you get report that character is moving even when player does not touch his joystick you will know where the problem is.

---

<div class="post-metadata">

**Author:** ![franck](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/7ba0ec/32.png) [@franck](https://discourse.libsdl.org/u/franck)\
**Post date:** [April 13, 2018, 4:46am UTC](https://discourse.libsdl.org/t/problem-with-analog-stick-on-linux/24197/3 "2018-04-13T04:46:02Z")

</div>

@es5804 Thanks for your input

---

<div class="post-metadata">

**Author:** ![franck](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/7ba0ec/32.png) [@franck](https://discourse.libsdl.org/u/franck)\
**Post date:** [April 13, 2018, 5:51am UTC](https://discourse.libsdl.org/t/problem-with-analog-stick-on-linux/24197/4 "2018-04-13T05:51:42Z")

</div>

@es5804 Any clue what’s the recommended JOYSTICK\_DEAD\_ZONE value ?

---

<div class="post-metadata">

**Author:** ![es5804](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@es5804](https://discourse.libsdl.org/u/es5804)\
**Post date:** [April 13, 2018, 3:27pm UTC](https://discourse.libsdl.org/t/problem-with-analog-stick-on-linux/24197/5 "2018-04-13T15:27:51Z")

</div>

I use 15% (4915) deadzone as default, but some old or cheap joystick may need more. The best is to have an option in your menu.  
However because you use the joystick as a logical input I think 8000 is fine.
