Taking input from a joystick with C# .NET

前端 未结 4 1488
-上瘾入骨i
-上瘾入骨i 2020-12-01 04:16

I searched around on Google for this, but the only things I came up with were outdated and did not work.

Does anyone have any information on how to get joystick data

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 04:27

    Google led me here and while not a requirement of this question, OpenTK is a good option for Windows and Linux (under mono) support.

    From the OpenTK docs, this code works on Raspberry Pi + Raspbian + Mono 3.12.0:

    for (int i = 0; i < 4; i++)
    {
        var state = Joystick.GetState(i);
        if (state.IsConnected)
        {
            float x = state.GetAxis(JoystickAxis.Axis0);
            float y = state.GetAxis(JoystickAxis.Axis1);
    
            // Print the current state of the joystick
            Console.WriteLine(state);
        }
    }
    

提交回复
热议问题